I am having some conflicts with the "Enhance Contrast" command in ImageJ and would like to know if anyone has insight into the two problems I am experiencing. I have written a simple macro to run thru a series of tiff images and enhance the contrast using normalization and then save each image as a jpeg. My two problems are as follows:
1) The macro saves each image successfully as a jpeg but when I go back and open them, only a few of them actually had the contrast enhanced, and some only had the contrast enhanced in a portion of the image down to a vertical line thru the image. 2) If I open one of the images in LabVIEW (one that was successfully enhanced in ImageJ), the image appears nearly inverted in greyscale, but not completely because if I invert the image greyscale, it still does not look correct. Has anyone seen anything like this or have any ideas how to resolve either of these problems? Thanks! -Liz |
Hi,
On Thu, 22 Jul 2010, Elizabeth Frink wrote: > I am having some conflicts with the "Enhance Contrast" command in ImageJ > and would like to know if anyone has insight into the two problems I am > experiencing. I have written a simple macro to run thru a series of tiff > images and enhance the contrast using normalization and then save each > image as a jpeg. My two problems are as follows: > > 1) The macro saves each image successfully as a jpeg but when I go back > and open them, only a few of them actually had the contrast enhanced, > and some only had the contrast enhanced in a portion of the image > down to a vertical line thru the image. > > 2) If I open one of the images in LabVIEW (one that was successfully > enhanced in ImageJ), the image appears nearly inverted in greyscale, > but not completely because if I invert the image greyscale, it still > does not look correct. > Has anyone seen anything like this or have any ideas how to resolve > either of these problems? Can you show your macro? Ciao, Johannes |
Below is my macro (I have shortened the first two lines by replacing a portion of the directory with "..." for illustration purposes only)
sourcedir = "C:\\Users\\Liz\\Documents\\...\\Brightfield\\1st Tear\\"; outdir = "C:\\Users\\Liz\\Documents\\...\\EnhCont\\1st Tear\\"; img = "sam6close_tear_00001-brightfield.tif"; numimg = 240; start = 1; for (i=0; i<numimg; i++) { imnum = start + i; strimnum = toString(imnum); inimg = substring(img,0,(lengthOf(img)-(16+lengthOf(strimnum)))) +strimnum + "-brightfield.tif"; infile = sourcedir + inimg; open(infile); run("Enhance Contrast", "saturated=0.4"); imgname = substring(inimg,0,(lengthOf(inimg)-16)) + "-contrast.jpg"; outfile = outdir + imgname; saveAs("Jpeg", outfile); close(); } Thanks! -Liz From: "Johannes Schindelin" <[hidden email]> To: "Elizabeth Frink" <[hidden email]> Cc: [hidden email] Sent: Friday, July 23, 2010 5:16:04 AM Subject: Re: Contrast Enhancement Hi, On Thu, 22 Jul 2010, Elizabeth Frink wrote: > I am having some conflicts with the "Enhance Contrast" command in ImageJ > and would like to know if anyone has insight into the two problems I am > experiencing. I have written a simple macro to run thru a series of tiff > images and enhance the contrast using normalization and then save each > image as a jpeg. My two problems are as follows: > > 1) The macro saves each image successfully as a jpeg but when I go back > and open them, only a few of them actually had the contrast enhanced, > and some only had the contrast enhanced in a portion of the image > down to a vertical line thru the image. > > 2) If I open one of the images in LabVIEW (one that was successfully > enhanced in ImageJ), the image appears nearly inverted in greyscale, > but not completely because if I invert the image greyscale, it still > does not look correct. > Has anyone seen anything like this or have any ideas how to resolve > either of these problems? Can you show your macro? Ciao, Johannes |
We use this script to count particles in a stack and use enhance
contrast in the stack. See if this may help. Andy Kligerman US EPA run("Image Sequence...", "open=F:\\runtest\\1.tif number=5 starting=1 increment=1 scale=100 file="); run("RGB Split"); run("Close"); run("Close"); run("Median...", "radius=3 stack"); for (slice=1; slice<=nSlices; slice++) {run("Set Slice...", "slice="+slice); run("Enhance Contrast", "saturated=0.3 normalize ");} setThreshold(0, 142); run("Convert to Mask", "stack"); run("Options...", "iterations=3 count=1 edm=Overwrite do=nothing stack"); run("Fill Holes", "stack"); run("Open","stack"); run("Watershed","stack"); run("Analyze Particles...", "size=250-Infinity circularity=0.75-1.00 show=Masks display exclude clear summarize stack"); run("Stack to Images"); |
In reply to this post by Elizabeth Frink
ImageJ Interest Group <[hidden email]> schrieb am 22.07.2010 23:50:21:
> 1) The macro saves each image successfully as a jpeg but when I go > back and open them, only a few of them actually had the contrast > enhanced, and some only had the contrast enhanced in a portion of > the image down to a vertical line thru the image. > > 2) ................... > > Has anyone seen anything like this or have any ideas how to resolve > either of these problems? I see no particular problem with your script, however, your description of 1) seems to indicate that the enhanced file is somehow written **before** the process is finished. No idea, if this should/can happen with the "run" command, but for a quick test, can you add wait(2000) (or a similar value) below the run command and see if anything changes? WRT your 2), no idea, seems to be an incompatible format!? Sincerely Joachim ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ |
In reply to this post by Elizabeth Frink
Hi,
On Fri, 23 Jul 2010, Elizabeth Frink wrote: > Below is my macro (I have shortened the first two lines by replacing a > portion of the directory with "..." for illustration purposes only) > > > sourcedir = "C:\\Users\\Liz\\Documents\\...\\Brightfield\\1st Tear\\"; > outdir = "C:\\Users\\Liz\\Documents\\...\\EnhCont\\1st Tear\\"; > img = "sam6close_tear_00001-brightfield.tif"; > numimg = 240; > start = 1; > > > for (i=0; i<numimg; i++) { > > imnum = start + i; > strimnum = toString(imnum); > inimg = substring(img,0,(lengthOf(img)-(16+lengthOf(strimnum)))) +strimnum + "-brightfield.tif"; > infile = sourcedir + inimg; > open(infile); > run("Enhance Contrast", "saturated=0.4"); > imgname = substring(inimg,0,(lengthOf(inimg)-16)) + "-contrast.jpg"; > outfile = outdir + imgname; > saveAs("Jpeg", outfile); > close(); > } Thanks. I could imagine that there is a timing problem, which you can work around by calling setBatchMode(true); at the start of the macro (and you can turn it off at the end with setBatchMode(false);). Ciao, Johannes |
Thanks Johannes (and everyone else) for your suggestions!
The setBatchMode command solved the problem with incomplete and partial contrast enhancements. I will see if I can find some sort of incompatibility issue with LabVIEW and the ImageJ images I have created, with regard to my second conflict. -Liz From: "Johannes Schindelin" <[hidden email]> To: "Elizabeth Frink" <[hidden email]> Cc: [hidden email] Sent: Friday, July 23, 2010 10:25:27 AM Subject: Re: Contrast Enhancement Hi, On Fri, 23 Jul 2010, Elizabeth Frink wrote: > Below is my macro (I have shortened the first two lines by replacing a > portion of the directory with "..." for illustration purposes only) > > > sourcedir = "C:\\Users\\Liz\\Documents\\...\\Brightfield\\1st Tear\\"; > outdir = "C:\\Users\\Liz\\Documents\\...\\EnhCont\\1st Tear\\"; > img = "sam6close_tear_00001-brightfield.tif"; > numimg = 240; > start = 1; > > > for (i=0; i<numimg; i++) { > > imnum = start + i; > strimnum = toString(imnum); > inimg = substring(img,0,(lengthOf(img)-(16+lengthOf(strimnum)))) +strimnum + "-brightfield.tif"; > infile = sourcedir + inimg; > open(infile); > run("Enhance Contrast", "saturated=0.4"); > imgname = substring(inimg,0,(lengthOf(inimg)-16)) + "-contrast.jpg"; > outfile = outdir + imgname; > saveAs("Jpeg", outfile); > close(); > } Thanks. I could imagine that there is a timing problem, which you can work around by calling setBatchMode(true); at the start of the macro (and you can turn it off at the end with setBatchMode(false);). Ciao, Johannes |
Hi Liz,
to me it looks like a race condition in ImageProcessor.createImage, which is used for saving a JPEG image. To understand the problem, some more information is needed: - Image type: 8, 16 or 32(float) bits? - Java 1.5 or 1.6? - Which operating system? Michael ________________________________________________________________ On 23 Jul 2010, at 18:14, Elizabeth Frink wrote: > Thanks Johannes (and everyone else) for your suggestions! > > > The setBatchMode command solved the problem with incomplete and > partial contrast enhancements. I will see if I can find some sort > of incompatibility issue with LabVIEW and the ImageJ images I have > created, with regard to my second conflict. > > > -Liz > > > From: "Johannes Schindelin" <[hidden email]> > To: "Elizabeth Frink" <[hidden email]> > Cc: [hidden email] > Sent: Friday, July 23, 2010 10:25:27 AM > Subject: Re: Contrast Enhancement > > Hi, > > On Fri, 23 Jul 2010, Elizabeth Frink wrote: > >> Below is my macro (I have shortened the first two lines by >> replacing a >> portion of the directory with "..." for illustration purposes only) >> >> >> sourcedir = "C:\\Users\\Liz\\Documents\\...\\Brightfield\\1st Tear\ >> \"; >> outdir = "C:\\Users\\Liz\\Documents\\...\\EnhCont\\1st Tear\\"; >> img = "sam6close_tear_00001-brightfield.tif"; >> numimg = 240; >> start = 1; >> >> >> for (i=0; i<numimg; i++) { >> >> imnum = start + i; >> strimnum = toString(imnum); >> inimg = substring(img,0,(lengthOf(img)-(16+lengthOf(strimnum)))) >> +strimnum + "-brightfield.tif"; >> infile = sourcedir + inimg; >> open(infile); >> run("Enhance Contrast", "saturated=0.4"); >> imgname = substring(inimg,0,(lengthOf(inimg)-16)) + "-contrast.jpg"; >> outfile = outdir + imgname; >> saveAs("Jpeg", outfile); >> close(); >> } > > Thanks. > > I could imagine that there is a timing problem, which you can work > around > by calling setBatchMode(true); at the start of the macro (and you > can turn > it off at the end with setBatchMode(false);). > > Ciao, > Johannes |
Michael,
The images are 16-bit, it is Java 1.6 and Windows Vista. I think I found the problem yesterday however - I was using images that I had divided by a 48-bit RGB instead of the 16-bit version of the same image. LabVIEW and ImageJ seem to be agreeing with each other much better now. Thanks! -Liz Liz Frink Laboratory Supervisor Graduate Research Assistant Graduate Nuclear or Mechanical Engineering Students (GNOMES) President Mechanical Testing and Evaluation Laboratory Mechanical Engineering - Kansas State University [hidden email] From: "Michael Schmid" <[hidden email]> To: [hidden email] Sent: Tuesday, July 27, 2010 4:27:18 AM Subject: Re: Contrast Enhancement Hi Liz, to me it looks like a race condition in ImageProcessor.createImage, which is used for saving a JPEG image. To understand the problem, some more information is needed: - Image type: 8, 16 or 32(float) bits? - Java 1.5 or 1.6? - Which operating system? Michael ________________________________________________________________ On 23 Jul 2010, at 18:14, Elizabeth Frink wrote: > Thanks Johannes (and everyone else) for your suggestions! > > > The setBatchMode command solved the problem with incomplete and > partial contrast enhancements. I will see if I can find some sort > of incompatibility issue with LabVIEW and the ImageJ images I have > created, with regard to my second conflict. > > > -Liz > > > From: "Johannes Schindelin" <[hidden email]> > To: "Elizabeth Frink" <[hidden email]> > Cc: [hidden email] > Sent: Friday, July 23, 2010 10:25:27 AM > Subject: Re: Contrast Enhancement > > Hi, > > On Fri, 23 Jul 2010, Elizabeth Frink wrote: > >> Below is my macro (I have shortened the first two lines by >> replacing a >> portion of the directory with "..." for illustration purposes only) >> >> >> sourcedir = "C:\\Users\\Liz\\Documents\\...\\Brightfield\\1st Tear\ >> \"; >> outdir = "C:\\Users\\Liz\\Documents\\...\\EnhCont\\1st Tear\\"; >> img = "sam6close_tear_00001-brightfield.tif"; >> numimg = 240; >> start = 1; >> >> >> for (i=0; i<numimg; i++) { >> >> imnum = start + i; >> strimnum = toString(imnum); >> inimg = substring(img,0,(lengthOf(img)-(16+lengthOf(strimnum)))) >> +strimnum + "-brightfield.tif"; >> infile = sourcedir + inimg; >> open(infile); >> run("Enhance Contrast", "saturated=0.4"); >> imgname = substring(inimg,0,(lengthOf(inimg)-16)) + "-contrast.jpg"; >> outfile = outdir + imgname; >> saveAs("Jpeg", outfile); >> close(); >> } > > Thanks. > > I could imagine that there is a timing problem, which you can work > around > by calling setBatchMode(true); at the start of the macro (and you > can turn > it off at the end with setBatchMode(false);). > > Ciao, > Johannes |
Free forum by Nabble | Edit this page |