New Script: PixelMath User Interface

Mike1485

Well-known member
Have you ever coded up a PixelMath instance and thought: wouldn't it be great if I could change these parameters with a slider and see the effects in a real-time preview? Well, if so, this new script is for you!

PixelMathUI, or PMUI, allows you to build a graphical user interface to any PixelMath instance. In effect PMUI lets you turn your PixelMath into a fully functional script, literally in minutes! (We call these scriptlets to reflect their basic script like characteristics but recognising they are not stand alone but require PMUI to run.)

I have worked closely with Bill Blanshan on this project and his ideas, testing and encouragement have been invaluable. Bill has produced a video introducing the new script which is available here on his YouTube channel. He will follow this up with a series of additional videos covering different aspects of PMUI. There is also full documentation accessible from within the script - we strongly advise you to read this to get the best from PMUI.

On multiple occasions I have been approached by people who have created useful PixelMath code and want help to turn it into a script. I hope that PMUI will help a whole range of people do just that. The result can be saved, reused and shared, much like a script. This means anyone producing a useful PMUI scriptlet can easily share it with the community.

Bill has produced over 20 scriptlets that ship with PMUI. These provide great examples of what can be done with PixelMath and how to integrate this into a PMUI interface. Even if you don’t think you will use PMUI to produce your own work, you may find it worth installing, just to get access to Bill’s scriptlets.

PMUI, and all of Bill’s scriptlets, can be downloaded by adding the following repository to your repository list:

https://www.cosmicphotons.com/pi-scripts/pixelmathui/

Note that PMUI simply provides an alternative way to harness the immense power and fuctionality of PixInsight’s native PixelMath process. However, the PixInsight team have had no hand in developing PMUI so any bugs etc are our sole responsibility! Please report anything you find on this thread.

Below is an example of a PixelMath interface built using PMUI. A fully functional interface like this can be built in minutes.

PMUIExample.jpg
 
Last edited:
this is really fantastic. in his opening bill says that a PMUI instance could be turned into a real script and it would run much faster. is there that much of a performance hit here, or did he mean if a particular PMUI script is compelling, you could turn it into a process for more speed?

also it might be helpful to just put index.html at the root of the repository with brief instructions to install the repo in PI. at the very least it lets ordinary people test if they are able to reach your server with a web browser.

rob
 
Thanks Rob.

I agree a more useful index.html would be a good idea. It has been on my "to-do" list for a while but I should get round it!

Regarding speed, if the PixelMath gets very involved there are often ways to streamline the calculations. That may be pre-calculating certain elements that are constant then hard coding that into the generated PixelMath, or maybe certain elements can be more efficiently done using available processes in PI etc etc. PMUI does its best but it can't do a critical appraisal of what the PixelMath is doing and find any efficiencies that could be made. And yes, of course, turning into a process is also possible if it is warranted.

CS, Mike
 
Tried this yesterday with a few of my simple, two-parameter PixelMath routines and it worked as advertised.

Thanks for this useful tool.

I would, however, like to have the ability to change parameter values by just using the up/down arrow keys rather than having to use the mouse to set a slider or even having to edit a value.

Thus, with a slider control set to something like 0.125 I could select that numeric field and press the up arrow key to change to 0.126 or when pressing the down arrow change the value to 0.124, etc.

Then, perhaps if possible, have the value change by five units in the least significant digit if you press up/down arrow with the shift key. So, if the current value was 0.124 and you press shift up arrow the new value would be 0.129.
 
Last edited:
Hi Mike,

This looks like a great script that will allow those of us who don't know how to code to accomplish some things!

In my first tests I encountered a problem and I'm wondering if I'm missing something?

I'm trying to combine two images: a star field (identifier Crater) and a constellation annotation (identifier Crater_Annotated), which is an image with a transparency layer.

With the simple Pixelmath formula $T+Crater_Annotated, I can use PixelmathUI as expected and get a preview of the combined images.
Capture d'écran 2025-05-04 105549 (Small).jpg

I can also change the Annotation Layer with another image and the preview reflects the change

But to better handle the transparency of the annotation, I want to use the following formula:$T+pixel(Crater_Annotated,x(),y(),3)*pixel(Crater_Annotated,x(),y())

This formula works if I use it directly in Pixelmath but the preview doesn't work in PixelmathUI:
Capture d'écran 2025-05-04 105839 (Small).jpg


And, as far as I can tell, the console doesn't report any problem:
Code:
PixelMath: Processing preview: temp->tempPreview
Executing PixelMath expression:
(Crater)+pixel(Crater_Annotated,x(),y(),3)*pixel(Crater_Annotated,x(),y());

combined RGB/K channels: done
Truncating to [0,1]: done
109.959 ms
0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  47%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  31%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%
Writing swap files...
778.756 MiB/s

PixelMath: Processing preview: temp->tempPreview
Executing PixelMath expression:
(Crater)+pixel(Crater_Annotated_2,x(),y(),3)*pixel(Crater_Annotated_2,x(),y());

combined RGB/K channels: done
Truncating to [0,1]: done
132.877 ms
0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  31%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  47%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%
Writing swap files...
708.219 MiB/s

PixelMath: Processing preview: temp->tempPreview
Executing PixelMath expression:
(Crater)+pixel(Crater_Annotated,x(),y(),3)*pixel(Crater_Annotated,x(),y());

combined RGB/K channels: done
Truncating to [0,1]: done
118.047 ms

Here are the 2 images in case you need them:
https://1drv.ms/f/c/1434990e98a7f003/EiVGNDli7xFAi5h6Mw-4DjcBc0oJ5Fv0_gjlqoJOlsl_Pg?e=UZKik4
 
On my MacBook the script doesn't load into the script drop-down menu.
I also put the StarReduction stript in the Repositories and that loads into CosmicPhotons in Scripts.

The script does load and run if I use "Execute Script File...".

Am I doing something wrong?
 
Hi Mike,

This looks like a great script that will allow those of us who don't know how to code to accomplish some things!

In my first tests I encountered a problem and I'm wondering if I'm missing something?

I'm trying to combine two images: a star field (identifier Crater) and a constellation annotation (identifier Crater_Annotated), which is an image with a transparency layer.

With the simple Pixelmath formula $T+Crater_Annotated, I can use PixelmathUI as expected and get a preview of the combined images.
View attachment 27181
I can also change the Annotation Layer with another image and the preview reflects the change

But to better handle the transparency of the annotation, I want to use the following formula:$T+pixel(Crater_Annotated,x(),y(),3)*pixel(Crater_Annotated,x(),y())

This formula works if I use it directly in Pixelmath but the preview doesn't work in PixelmathUI:
View attachment 27182

And, as far as I can tell, the console doesn't report any problem:
Code:
PixelMath: Processing preview: temp->tempPreview
Executing PixelMath expression:
(Crater)+pixel(Crater_Annotated,x(),y(),3)*pixel(Crater_Annotated,x(),y());

combined RGB/K channels: done
Truncating to [0,1]: done
109.959 ms
0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  47%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  31%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%
Writing swap files...
778.756 MiB/s

PixelMath: Processing preview: temp->tempPreview
Executing PixelMath expression:
(Crater)+pixel(Crater_Annotated_2,x(),y(),3)*pixel(Crater_Annotated_2,x(),y());

combined RGB/K channels: done
Truncating to [0,1]: done
132.877 ms
0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  31%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%0.007963305103628653
0.006198709085896933
0.008099043258629758
lnkC0 = 0.12184909071634624
lnkM = 0.05981290136153076
Processing channel #0:
Histogram transformation:  47%
Processing channel #1:
Histogram transformation:   0%
Processing channel #2:
Histogram transformation:   0%
Writing swap files...
708.219 MiB/s

PixelMath: Processing preview: temp->tempPreview
Executing PixelMath expression:
(Crater)+pixel(Crater_Annotated,x(),y(),3)*pixel(Crater_Annotated,x(),y());

combined RGB/K channels: done
Truncating to [0,1]: done
118.047 ms

Here are the 2 images in case you need them:
https://1drv.ms/f/c/1434990e98a7f003/EiVGNDli7xFAi5h6Mw-4DjcBc0oJ5Fv0_gjlqoJOlsl_Pg?e=UZKik4
Thanks for raising this. The issue is the use of the absolute x() and y() functions. These are pixel coordinates on the target image. In a preview the target image will typically have been rescaled but the auxiliary image (Crater_Annotated) has not been. Therefore the x() and y() coordinates on the auxiliary image will return the wrong pixel value. The work around is to avoid absolute pixel coordinate references like this and always use relative references. In your case the following works.

Code:
.symbols x, y;
x = X()*w(Crater_Annotated);
y = Y()*h(Crater_Annotated);
$T+pixel(Crater_Annotated,x,y,3)*pixel(Crater_Annotated,x,y);

For a future release I have a few ideas for resolving this issue but for now please avoid absolute pixel coordinate references. I had meant to mention this limitation in the documentation but unfortunately omitted to do so.
 
On my MacBook the script doesn't load into the script drop-down menu.
I also put the StarReduction stript in the Repositories and that loads into CosmicPhotons in Scripts.

The script does load and run if I use "Execute Script File...".

Am I doing something wrong?
That sounds odd. Does Resources>Updates>View Installed Updates suggest the script has been installed? If so can you find and install it manually via the Feature Scripts facility?
 
Thanks for raising this. The issue is the use of the absolute x() and y() functions. These are pixel coordinates on the target image. In a preview the target image will typically have been rescaled but the auxiliary image (Crater_Annotated) has not been. Therefore the x() and y() coordinates on the auxiliary image will return the wrong pixel value. The work around is to avoid absolute pixel coordinate references like this and always use relative references. In your case the following works.

Code:
.symbols x, y;
x = X()*w(Crater_Annotated);
y = Y()*h(Crater_Annotated);
$T+pixel(Crater_Annotated,x,y,3)*pixel(Crater_Annotated,x,y);

For a future release I have a few ideas for resolving this issue but for now please avoid absolute pixel coordinate references. I had meant to mention this limitation in the documentation but unfortunately omitted to do so.
Thanks Mike for the explanation and detailed workaround.
 
On my Linux Ubuntu with latest PI the script is causing computer hang up and finally crashing PixInsight. Every attempt to download scriplets by clicking small "up triangle with underscore" on the bottom of the script window - script is hanging up and, after some time, PixInsight is crashing and closing.

I can see my own pixelMath scripts which are on the screen in actual workspace but cannot download any other scripts.

I did clear all scripts in Resources->Updates->Reset Updates then restarted PI and downloaded all scripts again but no change.


EDIT: In ->View Installed Updates pixelmathui seems to be fully installed and is opening but then crashing.
 
On my Linux Ubuntu with latest PI the script is causing computer hang up and finally crashing PixInsight. Every attempt to download scriplets by clicking small "up triangle with underscore" on the bottom of the script window - script is hanging up and, after some time, PixInsight is crashing and closing.

I can see my own pixelMath scripts which are on the screen in actual workspace but cannot download any other scripts.

I did clear all scripts in Resources->Updates->Reset Updates then restarted PI and downloaded all scripts again but no change.


EDIT: In ->View Installed Updates pixelmathui seems to be fully installed and is opening but then crashing.
This is very odd - I have just downloaded and launched on Kubuntu 24.04.2 and everything seems to be working perfectly. Are you having problems with any other PI scripts/processes? Have you tried a complete reboot of your computer and try again?
 
Yes, I did it several times. Yes I have many other scripts - including yours :-) - and all of them apparently working well. No single issue with any other script or process. The system is configured with CUDA (for BXT speed) and machine is quite powerfull:
Screenshot_20250505_232557.png



Result is always same:



Screenshot_20250505_231834.png
 
I am sorry you are having these problems. I have tried but I cannot reproduce the issue on my machine (which is not as powerful as yours!) Unfortunately, without being able to reproduce it, I'm not sure I will be able to figure out what is happening. There is a report on Bill's You Tube channel of someone having the same issue on Linux - is that by any chance you as well, or is it maybe someone else with the same issue?
 
Hi Mike,

On Bill's You Tube is also me:-) My problem is that I don't even know where to look for. It is highly probable that the issue is in Linux itself - either some library or CUDA or... whatever. The system has been reinstalled from scratch some 2 months ago - I was doing some experiments with other Linux distributions. PixInsight under Linux AntiX is slightly faster but I had some problems with swap files. On the other distro I could not observe any improvement so I came back to Ubuntu.

Regards,
Wieslaw


EDIT: I will try to remove and re-install PixInsight today - will let you know results.
 
Last edited:
Hi Mike,

I did full re-installation of PixInsight - no success, all same. Below exactly what I did:

1. Remove PixInsight manually (deleting all files and folders using Terminal). CUDA files and folders removed too.
2. Download and install PixInsight.
3. sudo apt update && apt upgrade
4. PixInsight - update repositories (none added, only original for PI)
5. PI - Thread Performance Analysis
6. Repositories - PixelMathUI added/updated and PI restarted.

So it seems that the problem is either in Ubuntu itself or in PixelMathUI. Have no idea what else I could do with Linux - sudo apt update/upgrade has been done.

Wieslaw.
 
I'm sorry that has not worked. Unfortunately I am not a Linux expert, maybe forum members with Linux expertise may have other suggestions that will help ... ?
 
Hi Mike,

I become mad about this problem. Yes I'm daft - like all old people are :-)

I did re-install Ubuntu from scratch erasing entire disk. Then I install only basic programs like mail, browser and PixInsight at the end. Then I add only PixelMathUI to repository and... ALL IS WORKING WELL! :-) So the only conclusion is Linux/Ubuntu was a reson for failures. That's a good thing. Bad thing is that I don't know what/how/why it happens. I will be installing all other elements like scripts, CUDA with caution frequently checking if they are not causing same or similar problem. It is possible that there is some conflict with CUDA, NVIDIA drivers (well known "standard" story) or whatever :-) .

If I find what was causing problems will let you know - in this thread as it may be of use for the others. It will take 2-3 days before I will finish all installations. Obviously I will report here final result.


Regards,
Wieslaw
 
Thanks for the report back Wieslaw. I'm glad you have got PMUI working and I admire your persistence - I only hope you will feel it will deserve your perseverance! I look forward to knowing if you do manage to pinpoint the trouble causer.
CS, Mike
 
This is very odd - I have just downloaded and launched on Kubuntu 24.04.2 and everything seems to be working perfectly. Are you having problems with any other PI scripts/processes? Have you tried a complete reboot of your computer and try again?
Hi Mike, I may have some useful information for you since I had the same issue as Wieslaw on Kunbuntu 24.04.2. i.e when trying to "Load scriptlet" the interface would freeze and eventually I would have to kill the Pixinsight process. Initially the Pixel Math UI was working fine - I was able to select and run the "hosted" scriptlets. I then imported my own pixel math expression but quit out of Pixel Math UI without saving it to a scriptlet. After that I would get the Pixel Math UI lockup every time I tried to "Load scriptlet". Eventually the problem seemed to clear when I imported a very simple pixel math expression and did a "Save scriptlet". The whole Pixel Math UI script has been running fine ever since.

I also have Pixinsight running on my macmini. The Pixl Math UI script runs fine on that machine, however I do get an error in the console window:

1746660133972.png


Looking at the initial path for the "My scriptlets directory" - it seems to be set to the root of my system disk. I also noticed that "Include sub-directories" is checked by default. If I uncheck "Include sub-directories" then the "Launch Scriptlet" screen appears much quicker and the error message is no longer generated in the console.

I wonder if the initial settings for the "Launch Scriptlet" window are causing the issues on Linux. Both my installations are running fine now and I am really liking the Pixel Math UI script.

Thank you

Derek
 
Last edited:
Back
Top