Tiny problem in PixelMath

Bernhard

New member
Hi!

This is my first post, so here is an short intro: my name is Bernhard, I live in Salzburg, Austria and I am doing astrophotography for over 20 years with some years break between. My second start in astrophotography I did with PixInsight, and I really enjoy working with this great software.
Now, finally, I think I need your help.

I´d like to apply this operation to an image:

translate(grey, round((25-10)*random()+10), 10)

This should shift the image "grey" a random number of pixels between 10 and 25 in x-axes and 10 pixels in y-axes.
But I always get the error message

"*** Error: translate() argument #1: Must be an image reference or a functional subexpression evaluating to an image"

Without using the random-function the translation works fine, e.g.

translate(grey, 7, 10)

Can please someone tell me what I am doing wrong?

Kind regards,
Bernhard
 
"*** Error: translate() argument #1: Must be an image reference or a functional subexpression evaluating to an image"
I think this is the wrong error message. I think the real error relates to the constraint that the second and third arguments must be "an invariant scalar subexpression". If, for example, you try:
translate (grey, x(), 20)
you get error:
PixelMath: Processing view: grey

*** Error: translate() argument #2: The X-axis increment must be an invariant scalar subexpression

<* failed *>
However, if you try:
translate(grey, 10+x(), 20)
You get:
PixelMath: Processing view: grey

*** Error: translate() argument #1: Must be an image reference or a functional subexpression evaluating to an image

<* failed *>
This is clearly the same issue, but misreported as an issue with argument #1.
The bottom line is you simply can't do what you are trying to do; the "generator" options generate a single static image that is used for the whole PixelMath evaluation - they can't vary from pixel to pixel.
 
Fred beat me to it. The random() function will be recalculated for every pixel but for the translate generator to work the second parameter needs to be a fixed value for the whole image. What are you actually trying to do here? If we know that there probably is a way to achieve it!
 
Ah, of course - I thought random() will generate one number for the whole image, I clearly understand now.

I have a plenty number of simulated light frames. These frames are actually dark frames, but they should simulate my light frames.
I´d like to test some variations in image calibration with or without darks, bias´, flats and darkflats regarding to the resulting noise in the final image.
So I want to simulate dither in these simulated light frames. My idea was to create a pixelmath-process which is doing that random shift and apply it to all of my "lights". Sounds maybe a little freaky but I think, that after this small research I will better understand whats going on during image calibration.
 
Trying to guess what your intent was. The question is "what do you want in your output image at location (x, y)?".
One possibility is that you want this to be the pixel at (x+round((25-10)*random()+10), y+10) from the image "grey".
This is achieved simply by:

pixel (grey, x()+round((25-10)*random()+10), y()+10)

Because this is evaluated at every pixel, there is no static image involved.
 
... or you could run the following script.

JavaScript:
let view = ImageWindow.activeWindow.mainView;
let numberOfNewViews = 2;

let PM = new PixelMath();
PM.createNewImage = true;

for (let i = 0; i < numberOfNewViews; ++i)
{
   let dx = Math.round((25 - 10)*Math.random() + 10);
   let dy = 10;
   PM.expression = "translate($T, " + dx.toString() + ", " + dy.toString() + ")";
   PM.executeOn(view);
}

Change the number of new views in line 2 to however many "dithered" images you want. The script will create new images based on whatever is the current active image - so make sure your "grey" image is active.
 
Back
Top