Correcting Row Offsets?
Josh Walawender wrote on Jan 29, 2006
I've got some images which suffer from time variable noise which offsets each row of pixels by a small amount from the rows above and below it. The noise can be corrected in most cases by adding a small offset to each row such that the median of the row matches the median of the entire image. I've written a script to do this in IDL and it works beautifully, but I am looking for a way to do this in IRAF so that I can keep all my reductions in one script rather than jumping back and forth between IRAF and IDL.
Does anyone know of a clever way to do this? I've been looking for the right type of filter for it, but so far I haven't found anything that works nearly as well as my simple IDL routine.
thanks,
Josh
Does anyone know of a clever way to do this? I've been looking for the right type of filter for it, but so far I haven't found anything that works nearly as well as my simple IDL routine.
thanks,
Josh
Mike Fitzpatrick wrote on Jan 29, 2006
If I understand your problem correctly, to each row you want to add something like the difference between the median of the row and the median of the entire image, right? Not quite a one-liner but try
real im_mean
imstat (oldimage, fields="midpt", format-) | scan (im_mean)
imexpr ("a + (b - median(a))", newimage, a=oldimage, b=im_mean)
In the expression 'a' is processed for each line in the image, '(b-median(a))' is a scalar value that's the offset I think you're looking for. See the help pages for IMSTAT and IMEXPR for details.
Cheers,
-Mike
real im_mean
imstat (oldimage, fields="midpt", format-) | scan (im_mean)
imexpr ("a + (b - median(a))", newimage, a=oldimage, b=im_mean)
In the expression 'a' is processed for each line in the image, '(b-median(a))' is a scalar value that's the offset I think you're looking for. See the help pages for IMSTAT and IMEXPR for details.
Cheers,
-Mike
Josh Walawender wrote on Jan 29, 2006
If 'a' is processed for each line of the image, don't I need some kind of loop to run through each line? If so, how do I specify the appropriate image section within the loop?
-Josh
-Josh
Mike Fitzpatrick wrote on Jan 29, 2006
IMEXPR loops through the image rows automatically. What I means is that
'a' (in this case) is a vector operand containing all the pixels in a row of
the image, the expression is repeated/re-evaluated for each row. If you want
to operate on only a few rows then you can just tack the section onto the image name when you call it, or see the use of the I/J/K builtins for using the row/col/band number in the expression.
-Mike
'a' (in this case) is a vector operand containing all the pixels in a row of
the image, the expression is repeated/re-evaluated for each row. If you want
to operate on only a few rows then you can just tack the section onto the image name when you call it, or see the use of the I/J/K builtins for using the row/col/band number in the expression.
-Mike
Josh Walawender wrote on Jan 29, 2006
Sorry for dragging this on, but I'm still having trouble. Here is the code as I'm running it. I'm operating on image test1.fits and hoping to output the result to test2.fits:
real im_mean
imstat ("test1", fields="midpt", format-) | scan (im_mean)
imexpr ("a + (b - median(a)", "test2", a="test1", b=im_mean)
I get the following error after running the imexpr line:
ERROR: ambiguous parameter `a' within `<searchpath>'
Also, I still don't understand how this is looping though the rows of the image. Did I just get lucky and imexpr naturally loops through rows? Would this be different if I had to operate on columns?
thanks,
Josh
real im_mean
imstat ("test1", fields="midpt", format-) | scan (im_mean)
imexpr ("a + (b - median(a)", "test2", a="test1", b=im_mean)
I get the following error after running the imexpr line:
ERROR: ambiguous parameter `a' within `<searchpath>'
Also, I still don't understand how this is looping though the rows of the image. Did I just get lucky and imexpr naturally loops through rows? Would this be different if I had to operate on columns?
thanks,
Josh
Mike Fitzpatrick wrote on Jan 29, 2006
real im_mean
imstat ("test1", fields="midpt", format-) | scan (im_mean)
imexpr ("a + (b - median(a)", "test2", a="test1", b=im_mean)
Note there is a missing closed paren in your expression.
I get the following error after running the imexpr line:
ERROR: ambiguous parameter `a' within `<searchpath>'
The syntax above is the normal script 'program mode', the error message sometimes happens due to quirks in the CL and can usually be cleared by declaring a dummy parameter 'a' to avoid the message, e.g.
string a
real im_mean
:
Also, I still don't understand how this is looping though the rows of the image. Did I just get lucky and imexpr naturally loops through rows? Would this be different if I had to operate on columns?
Right, the task is meant to apply the expression to the entire image, it does so one-row at a time. If you wanted to work on columns I suppose you could simply IMTRANSPOSE the image before/after IMEXPR or loop using an image section.
-Mike
Josh Walawender wrote on Jan 29, 2006
That worked perfectly once I cleared the a and b parameters. Thanks!
Josh
Josh
Last post on Jan 29, 2006