Hi all,
I'm trying to add a value (p) to each of the images in my stack. This value (p) changes for each picture according to the function p= 5-mean. When i run the following code below, it runs but i find it to add "5" to all of my images not "5-mean" whatever "mean" is for that particular image. Any idea why it's doing this? getStatistics (mean); y=mean; p= 5.0000 - mean; run("Add...", + p +); |
Line by line: - getStatistics seems to require you to submit arguments in a particular order. i.e. getStatistics(area, mean); works fine, but getStatistics(mean) returns area rather than mean. At least, this has been my experience. - y=mean is unnecessary here. - p=5.0000-mean; no problems here. - no need for +'s here since you aren't adding numbers or strings. run("Add...", p); would work, as would run("Add...", 5-mean); Also be aware the value you add is for each pixel - the mean will not necessarily be 5 larger. You can check all of this with liberal use of the print function. I suggest the following: getStatistics(area, mean); p= 5.0000 - mean; run("Add...", p); And if you want to get a better idea of what the macro is actually doing... x=getPixel(500, 500) print(x); getStatistics(area, mean); y=mean; print(y); p= 5.0000 - mean; print(p); run("Add...", p); x=getPixel(500, 500) print(x); In this case the macro would check the value of a particular pixel at the coordinates 500 by 500 and print that value. It will also print the initial mean, 5-mean, and the final value of your pixel, in that order. Make sure 5-mean isn't a negative value, unless that's what you had in mind. |
In reply to this post by Ka Wai Tse
Hi,
it should be getStatistics(area, mean, min, max, std, histogram) or getStatistics(area, mean) Your macro will assigne the area to the 'mean' variable - it seems that the area of your images (in calibrated units) was almost zero... By the way, since the "Add..." function works on raw (uncalibrated) pixel values, it would be better to use getRawStatistics(nPixels, mean); Otherwise the macro won't work correctly for images with pixel value calibration. Michael ________________________________________________________________ On 24 Jun 2009, at 02:05, Ka Wai Tse wrote: > Hi all, > I'm trying to add a value (p) to each of the images in my stack. > This value > (p) changes for each picture according to the function p= 5-mean. > When i run > the following code below, it runs but i find it to add "5" to all > of my > images not "5-mean" whatever "mean" is for that particular image. > Any idea > why it's doing this? > > getStatistics (mean); > y=mean; > p= 5.0000 - mean; > run("Add...", + p +); |
In reply to this post by Aaron Schiffman
Thanks for the tips. i revised it to this... but still doesn't work.
n = getSliceNumber(); for (i=1; i<=nSlices; i++) { setSlice(i); makeRectangle(3, 0, 93, 315); getRawStatistics(nPixels, mean); p= 5.0000 - mean; print(p); makeRectangle(0, 0, 816, 1088); run("Add...",p); } explanation: the following is for applying my commands to all the images in my stack n = getSliceNumber(); for (i=1; i<=nSlices; i++) { setSlice(i); the following is to get the mean value of the square created in my image: makeRectangle(3, 0, 93, 315); getRawStatistics(nPixels, mean); the following is to add "5-mean" to the entire image....I printed p to make sure it's adding the correct value. p= 5.0000 - mean; print(p); makeRectangle(0, 0, 816, 1088); run("Add...",p); I find it to print the correct p but doesn't add it. It adds a constant 25 to all my images. Any ideas? ----- Original Message ----- From: Aaron Schiffman <[hidden email]> Date: Tuesday, June 23, 2009 8:02 pm Subject: Re: using variable with "add" function To: [hidden email] > Ka Wai Tse wrote: > > > > Hi all, > > I'm trying to add a value (p) to each of the images in my stack. > This> value > > (p) changes for each picture according to the function p= 5-mean. > When i > > run > > the following code below, it runs but i find it to add "5" to all > of my > > images not "5-mean" whatever "mean" is for that particular image. > Any idea > > why it's doing this? > > > > getStatistics (mean); > > y=mean; > > p= 5.0000 - mean; > > run("Add...", + p +); > > > > > > > Line by line: > > - getStatistics seems to require you to submit arguments in a > particularorder. i.e. getStatistics(area, mean); works fine, but > getStatistics(mean)returns area rather than mean. At least, this > has been my experience. > > - y=mean is unnecessary here. > > - p=5.0000-mean; no problems here. > > - no need for +'s here since you aren't adding numbers or strings. > run("Add...", p); would work, as would run("Add...", 5-mean); > > Also be aware the value you add is for each pixel - the mean will not > necessarily be 5 larger. You can check all of this with liberal use > of the > print function. I suggest the following: > > > getStatistics(area, mean); > p= 5.0000 - mean; > run("Add...", p); > > And if you want to get a better idea of what the macro is actually > doing... > > x=getPixel(500, 500) > print(x); > getStatistics(area, mean); > y=mean; > print(y); > p= 5.0000 - mean; > print(p); > run("Add...", p); > x=getPixel(500, 500) > print(x); > > In this case the macro would check the value of a particular pixel > at the > coordinates 500 by 500 and print that value. It will also print the > initialmean, 5-mean, and the final value of your pixel, in that > order. Make sure > 5-mean isn't a negative value, unless that's what you had in mind. > > > -- > View this message in context: http://n2.nabble.com/using-variable- > with-%22add%22-function-tp3145942p3146465.html > Sent from the ImageJ mailing list archive at Nabble.com. > |
In reply to this post by Michael Schmid
Thanks for the tips. i revised it to this... but still doesn't work.
n = getSliceNumber(); for (i=1; i<=nSlices; i++) { setSlice(i); makeRectangle(3, 0, 93, 315); getRawStatistics(nPixels, mean); p= 5.0000 - mean; print(p); makeRectangle(0, 0, 816, 1088); run("Add...",p); } explanation: the following is for applying my commands to all the images in my stack n = getSliceNumber(); for (i=1; i<=nSlices; i++) { setSlice(i); the following is to get the mean value of the square created in my image: makeRectangle(3, 0, 93, 315); getRawStatistics(nPixels, mean); the following is to add "5-mean" to the entire image....I printed p to make sure it's adding the correct value. p= 5.0000 - mean; print(p); makeRectangle(0, 0, 816, 1088); run("Add...",p); I find it to print the correct p but doesn't add it. It adds a constant 25 to all my images. Any ideas? ----- Original Message ----- From: Michael Schmid <[hidden email]> Date: Wednesday, June 24, 2009 1:33 am Subject: Re: using variable with "add" function To: [hidden email] > Hi, > > it should be > getStatistics(area, mean, min, max, std, histogram) > or > getStatistics(area, mean) > > Your macro will assigne the area to the 'mean' variable - it seems > that the area of your images (in calibrated units) was almost zero... > > By the way, since the "Add..." function works on raw (uncalibrated) > > pixel values, it would be better to use > getRawStatistics(nPixels, mean); > > Otherwise the macro won't work correctly for images with pixel > value > calibration. > > Michael > ________________________________________________________________ > > > On 24 Jun 2009, at 02:05, Ka Wai Tse wrote: > > > Hi all, > > I'm trying to add a value (p) to each of the images in my stack. > > This value > > (p) changes for each picture according to the function p= 5-mean. > > > When i run > > the following code below, it runs but i find it to add "5" to all > > > of my > > images not "5-mean" whatever "mean" is for that particular image. > > > Any idea > > why it's doing this? > > > > getStatistics (mean); > > y=mean; > > p= 5.0000 - mean; > > run("Add...", + p +); > |
Hi,
there is one more error in your macro that I did not notice before (sorry). It should be run("Add...", "value="+mean); You can see this if you run the Macro Recorder, it will record, e.g. run("Add...", "value=2"); If you have a variable, use the '+' operator for string concatenations; numbers will be automatically converted to strings. Michael ________________________________________________________________ On 24 Jun 2009, at 18:02, Ka Wai Tse wrote: > Thanks for the tips. i revised it to this... but still doesn't work. > > n = getSliceNumber(); > for (i=1; i<=nSlices; i++) { > setSlice(i); > makeRectangle(3, 0, 93, 315); > getRawStatistics(nPixels, mean); > p= 5.0000 - mean; > print(p); > makeRectangle(0, 0, 816, 1088); > run("Add...",p); > } > > explanation: > the following is for applying my commands to all the images in my > stack > > n = getSliceNumber(); > for (i=1; i<=nSlices; i++) { > setSlice(i); > > the following is to get the mean value of the square created in my > image: > makeRectangle(3, 0, 93, 315); > getRawStatistics(nPixels, mean); > > the following is to add "5-mean" to the entire image....I printed p > to make sure it's adding the correct value. > > p= 5.0000 - mean; > print(p); > makeRectangle(0, 0, 816, 1088); > run("Add...",p); > > I find it to print the correct p but doesn't add it. It adds a > constant 25 to all my images. > > Any ideas? > > ----- Original Message ----- > From: Michael Schmid <[hidden email]> > Date: Wednesday, June 24, 2009 1:33 am > Subject: Re: using variable with "add" function > To: [hidden email] > >> Hi, >> >> it should be >> getStatistics(area, mean, min, max, std, histogram) >> or >> getStatistics(area, mean) >> >> Your macro will assigne the area to the 'mean' variable - it seems >> that the area of your images (in calibrated units) was almost zero... >> >> By the way, since the "Add..." function works on raw (uncalibrated) >> >> pixel values, it would be better to use >> getRawStatistics(nPixels, mean); >> >> Otherwise the macro won't work correctly for images with pixel >> value >> calibration. >> >> Michael >> ________________________________________________________________ >> >> >> On 24 Jun 2009, at 02:05, Ka Wai Tse wrote: >> >>> Hi all, >>> I'm trying to add a value (p) to each of the images in my stack. >>> This value >>> (p) changes for each picture according to the function p= 5-mean. >> >>> When i run >>> the following code below, it runs but i find it to add "5" to all >> >>> of my >>> images not "5-mean" whatever "mean" is for that particular image. >> >>> Any idea >>> why it's doing this? >>> >>> getStatistics (mean); >>> y=mean; >>> p= 5.0000 - mean; >>> run("Add...", + p +); >> |
Free forum by Nabble | Edit this page |