Dear colleagues,
A simple need, but I could not find the right solution in ImageJ. I am sorry if it is obvious. Is there a filter to increase edge sharpness and reduce the effect known as "halo effect" in optical microscopy? At the edges of bright objects and a dark background (or vice-versa) there are normally pixels with intermediate pixel values. If other objects in the image have these pixel values, when they are segmented the edges of bright objects will also appear. Even though these fake edges can be corrected by a morphological open, it is normally better to pre-process the image with an edge enhancement filter (some times called delineate) to increase the edge sharpness and reduce the amount of intermediate pixels. Any hints? Thank you! Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEMa <http://www.dema.puc-rio.br/> - Departamento de Engenharia de Materiais PUC-Rio <http://www.puc-rio.br/> Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55)(21)3527-1243 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Sidnei,
There is a plugin called Image Edges from Thomas Boudier (I think it is not included in Fiji by default but available on the following site: http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start). Another possibility would be the "Edges" in FeatureJ from Eric Meijering which enables you to suppress "halo" effects. To my knowledge both plugins apply Canny edge detection based algorithms. regards, Jan -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Jan
I guess this is not quite the answer. I don't need edge detection, but edge enhancement. I couldn't figure how either of your hints would do it. The algorithm should be simple. Take a neighborhood, calculate min, max, and range R. Pick a threshold T. If T>R it is not an edge, keep input pixel. Else exchange pixel with max or min. I just don't know how to program it. Any other hints? Thank you. Em 22/06/2013 04:24, "Jan Brocher - BioVoxxel" <[hidden email]> escreveu: > Hi Sidnei, > > There is a plugin called Image Edges from Thomas Boudier (I think it is > not included in Fiji by default but available on the following site: > http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start > ). > Another possibility would be the "Edges" in FeatureJ from Eric Meijering > which enables you to suppress "halo" effects. To my knowledge both plugins > apply Canny edge detection based algorithms. > > regards, > Jan > > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Sidnei,
I am not sure if this will be a solution you are looking for, but have you considered unsharp masking (>Process > Filters > Unsharp Mask...). Another possibility might be the "Contrast Detection from the BioVoxxel Toolbox if you tick the option "enhance edges in original". This method applied grayscale erosion and dilation to enhance edges and thereny might lead to stronger edge enhancement than the unsharp mask but can also induce artifacts if overdone. kind regards, Jan 2013/6/22 Sidnei Paciornik <[hidden email]> > Hi Jan > I guess this is not quite the answer. I don't need edge detection, but > edge enhancement. I couldn't figure how either of your hints would do it. > The algorithm should be simple. Take a neighborhood, calculate min, max, > and range R. > Pick a threshold T. > If T>R it is not an edge, keep input pixel. > Else exchange pixel with max or min. > > I just don't know how to program it. > Any other hints? > Thank you. > Em 22/06/2013 04:24, "Jan Brocher - BioVoxxel" <[hidden email]> > escreveu: > >> Hi Sidnei, >> >> There is a plugin called Image Edges from Thomas Boudier (I think it is >> not included in Fiji by default but available on the following site: >> http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start >> ). >> Another possibility would be the "Edges" in FeatureJ from Eric Meijering >> which enables you to suppress "halo" effects. To my knowledge both plugins >> apply Canny edge detection based algorithms. >> >> regards, >> Jan >> >> -- CEO: Dr. rer. nat. Jan Brocher phone: +49 (0)6234 917 03 39 mobile: +49 (0)176 705 746 81 e-mail: [hidden email] info: [hidden email] inquiries: [hidden email] web: www.biovoxxel.de -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Jan,
Thanks again for the hints, which I did test. I guess the main drawaback is that these approaches tend to increase high frequency and contrast everywhere, not only at edges. They give me part of the improvemente I wanted, but also increasing noise within objects. Let us see if some other colleague can add to the discussion. Thank you! Sidnei On Sun, Jun 23, 2013 at 5:25 AM, BioVoxxel <[hidden email]> wrote: > Hi Sidnei, > > I am not sure if this will be a solution you are looking for, but have you > considered unsharp masking (>Process > Filters > Unsharp Mask...). > Another possibility might be the "Contrast Detection from the BioVoxxel > Toolbox if you tick the option "enhance edges in original". This method > applied grayscale erosion and dilation to enhance edges and thereny might > lead to stronger edge enhancement than the unsharp mask but can also induce > artifacts if overdone. > > kind regards, > Jan > > > 2013/6/22 Sidnei Paciornik <[hidden email]> > >> Hi Jan >> I guess this is not quite the answer. I don't need edge detection, but >> edge enhancement. I couldn't figure how either of your hints would do it. >> The algorithm should be simple. Take a neighborhood, calculate min, max, >> and range R. >> Pick a threshold T. >> If T>R it is not an edge, keep input pixel. >> Else exchange pixel with max or min. >> >> I just don't know how to program it. >> Any other hints? >> Thank you. >> Em 22/06/2013 04:24, "Jan Brocher - BioVoxxel" <[hidden email]> >> escreveu: >> >>> Hi Sidnei, >>> >>> There is a plugin called Image Edges from Thomas Boudier (I think it is >>> not included in Fiji by default but available on the following site: >>> http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start >>> ). >>> Another possibility would be the "Edges" in FeatureJ from Eric Meijering >>> which enables you to suppress "halo" effects. To my knowledge both plugins >>> apply Canny edge detection based algorithms. >>> >>> regards, >>> Jan >>> >>> > > > -- > > CEO: Dr. rer. nat. Jan Brocher > phone: +49 (0)6234 917 03 39 > mobile: +49 (0)176 705 746 81 > e-mail: [hidden email] > info: [hidden email] > inquiries: [hidden email] > web: www.biovoxxel.de > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi,
On Jun 23, 2013, at 3:11 PM, Sidnei Paciornik wrote: > Hi Jan, > > Thanks again for the hints, which I did test. > > I guess the main drawaback is that these approaches tend to increase high > frequency and contrast everywhere, not only at edges. They give me part of > the improvemente I wanted, but also increasing noise within objects. > > Let us see if some other colleague can add to the discussion. Can you post a small example in a public place so we can see what you are describing? Thanks, Ben > > Thank you! > > Sidnei > > > On Sun, Jun 23, 2013 at 5:25 AM, BioVoxxel <[hidden email]> wrote: > >> Hi Sidnei, >> >> I am not sure if this will be a solution you are looking for, but have you >> considered unsharp masking (>Process > Filters > Unsharp Mask...). >> Another possibility might be the "Contrast Detection from the BioVoxxel >> Toolbox if you tick the option "enhance edges in original". This method >> applied grayscale erosion and dilation to enhance edges and thereny might >> lead to stronger edge enhancement than the unsharp mask but can also induce >> artifacts if overdone. >> >> kind regards, >> Jan >> >> >> 2013/6/22 Sidnei Paciornik <[hidden email]> >> >>> Hi Jan >>> I guess this is not quite the answer. I don't need edge detection, but >>> edge enhancement. I couldn't figure how either of your hints would do it. >>> The algorithm should be simple. Take a neighborhood, calculate min, max, >>> and range R. >>> Pick a threshold T. >>> If T>R it is not an edge, keep input pixel. >>> Else exchange pixel with max or min. >>> >>> I just don't know how to program it. >>> Any other hints? >>> Thank you. >>> Em 22/06/2013 04:24, "Jan Brocher - BioVoxxel" <[hidden email]> >>> escreveu: >>> >>>> Hi Sidnei, >>>> >>>> There is a plugin called Image Edges from Thomas Boudier (I think it is >>>> not included in Fiji by default but available on the following site: >>>> http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start >>>> ). >>>> Another possibility would be the "Edges" in FeatureJ from Eric Meijering >>>> which enables you to suppress "halo" effects. To my knowledge both plugins >>>> apply Canny edge detection based algorithms. >>>> >>>> regards, >>>> Jan >>>> >>>> >> >> >> -- >> >> CEO: Dr. rer. nat. Jan Brocher >> phone: +49 (0)6234 917 03 39 >> mobile: +49 (0)176 705 746 81 >> e-mail: [hidden email] >> info: [hidden email] >> inquiries: [hidden email] >> web: www.biovoxxel.de >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Ben
Here is a link to a pdf that explains the point. https://dl.dropboxusercontent.com/u/20667937/Halo%20effect.pdf Regards, Sidnei On Sun, Jun 23, 2013 at 8:11 PM, Ben Tupper <[hidden email]> wrote: > Hi, > > On Jun 23, 2013, at 3:11 PM, Sidnei Paciornik wrote: > > > Hi Jan, > > > > Thanks again for the hints, which I did test. > > > > I guess the main drawaback is that these approaches tend to increase high > > frequency and contrast everywhere, not only at edges. They give me part > of > > the improvemente I wanted, but also increasing noise within objects. > > > > Let us see if some other colleague can add to the discussion. > > > Can you post a small example in a public place so we can see what you are > describing? > > Thanks, > Ben > > > > > Thank you! > > > > Sidnei > > > > > > On Sun, Jun 23, 2013 at 5:25 AM, BioVoxxel <[hidden email]> > wrote: > > > >> Hi Sidnei, > >> > >> I am not sure if this will be a solution you are looking for, but have > you > >> considered unsharp masking (>Process > Filters > Unsharp Mask...). > >> Another possibility might be the "Contrast Detection from the BioVoxxel > >> Toolbox if you tick the option "enhance edges in original". This method > >> applied grayscale erosion and dilation to enhance edges and thereny > might > >> lead to stronger edge enhancement than the unsharp mask but can also > induce > >> artifacts if overdone. > >> > >> kind regards, > >> Jan > >> > >> > >> 2013/6/22 Sidnei Paciornik <[hidden email]> > >> > >>> Hi Jan > >>> I guess this is not quite the answer. I don't need edge detection, but > >>> edge enhancement. I couldn't figure how either of your hints would do > it. > >>> The algorithm should be simple. Take a neighborhood, calculate min, > max, > >>> and range R. > >>> Pick a threshold T. > >>> If T>R it is not an edge, keep input pixel. > >>> Else exchange pixel with max or min. > >>> > >>> I just don't know how to program it. > >>> Any other hints? > >>> Thank you. > >>> Em 22/06/2013 04:24, "Jan Brocher - BioVoxxel" < > [hidden email]> > >>> escreveu: > >>> > >>>> Hi Sidnei, > >>>> > >>>> There is a plugin called Image Edges from Thomas Boudier (I think it > is > >>>> not included in Fiji by default but available on the following site: > >>>> > http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start > >>>> ). > >>>> Another possibility would be the "Edges" in FeatureJ from Eric > Meijering > >>>> which enables you to suppress "halo" effects. To my knowledge both > plugins > >>>> apply Canny edge detection based algorithms. > >>>> > >>>> regards, > >>>> Jan > >>>> > >>>> > >> > >> > >> -- > >> > >> CEO: Dr. rer. nat. Jan Brocher > >> phone: +49 (0)6234 917 03 39 > >> mobile: +49 (0)176 705 746 81 > >> e-mail: [hidden email] > >> info: [hidden email] > >> inquiries: [hidden email] > >> web: www.biovoxxel.de > >> > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Monday 24 Jun 2013 03:14:08 Sidnei Paciornik wrote:
> Here is a link to a pdf that explains the point. > > https://dl.dropboxusercontent.com/u/20667937/Halo%20effect.pdf I do not think this is a microscopy-only issue. Most digital images captured with a camera or scanner, if enlarged, will show some blurring around edges. There is a similar approach called Morphological Contrast or Toggle Contrast, described in Soille's book Morphological Image analysis p. 259. The procedure sets the pixel value to either Max or Min in a kernel, depending on which one is the closest to the original and so you do not need to rely on an arbitrary threshold. A macro to do this is in the Morphology zip file in my page (called Morphological_contrast.txt). However to modify this to do what you want is trivial. You do the above if the difference of max-min is above a threshold t. The original Morphological Contrast is the case when the threshold is 0. Below is the macro modified to do this. Mind the line breaks. Cheers Gabriel //---------------8<----------------- // Morphological_contrast_Thr // G. Landini 24/Jun/2013 // Sets the pixel value to either Max or Min, depending on which one is // the closest and above a set threshold // Similar to Toggle Contrast in Soille, Morphological Image Analysis (2004), // p. 259. // It can use operators other than Min and Max (ie Open and Close, etc) setBatchMode(true); if (bitDepth()!=24){ a=getTitle(); Dialog.create("Morphologica Contrast Thr"); Dialog.addNumber("Radius", 2); Dialog.addNumber("Threshold", 25); Dialog.show(); r=Dialog.getNumber(); t=Dialog.getNumber(); run("Duplicate...", "title=min"); run("Minimum...", "radius="+r); selectWindow(a); run("Duplicate...", "title=max"); run("Maximum...", "radius="+r); selectWindow("max"); w=getWidth(); h=getHeight(); i=0; max=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ max[i]=getPixel(x,y); i++; } } selectWindow("min"); i=0; min=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ min[i]=getPixel(x,y); i++; } } selectWindow(a); i=0; for (x=0;x<w;x++){ for (y=0;y<h;y++){ c=getPixel(x,y); if (max[i]-min[i]>t){ if((max[i]-c)<=(c-min[i])){ putPixel(x,y, max[i]); } else if ((max[i]-c)>(c-min[i])){ putPixel(x,y, min[i]); } } i++; } } updateDisplay(); selectWindow("min"); close(); selectWindow("max"); close(); } else showMessage("Error","Greyscale images only!\nConvert RGB to HSB and process\nthe Brightness channel only."); setBatchMode(false); //---------------8<----------------- -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sidnei Paciornik
Hi Sidnei,
some edge-preserving blur operations can also sharpen edges. As an example, you could try the 'Thresholded Blur' filter: http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:thresholded_blur:start Michael ________________________________________________________________ On Jun 22, 2013, at 04:27, Sidnei Paciornik wrote: > Dear colleagues, > > A simple need, but I could not find the right solution in ImageJ. I am > sorry if it is obvious. > > Is there a filter to increase edge sharpness and reduce the effect known as > "halo effect" in optical microscopy? > > At the edges of bright objects and a dark background (or vice-versa) there > are normally pixels with intermediate pixel values. If other objects in the > image have these pixel values, when they are segmented the edges of bright > objects will also appear. > > Even though these fake edges can be corrected by a morphological open, it > is normally better to pre-process the image with an edge enhancement filter > (some times called delineate) to increase the edge sharpness and reduce the > amount of intermediate pixels. > > Any hints? > > Thank you! > > Prof. Sidnei Paciornik > Grupo de Análise de Imagens e Microscopia Digital > DEMa <http://www.dema.puc-rio.br/> - Departamento de Engenharia de Materiais > PUC-Rio <http://www.puc-rio.br/> > Rua Marquês de São Vicente 225 > Prédio Leme, Sala 501L > Gávea - Rio de Janeiro - RJ > 22451-900 - Brasil > tel: (55)(21)3527-1243 > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Gabriel Landini
Hi Gabriel
I would like to refer to the message below, from 2013, in which you sent me the code for an edge enhancement (or delineation) algorithm in ImageJ. We have used it several times but recently, trying to apply it to a rather large image (18kx15k pixels), we had a strange behavior. The plugin takes about 15 minutes running (on an i7 with 24 Gb RAM) and then apparently finishes. However, the output image is the same as the input. There is no error message. Any suggestions? Thank you very much for your attention. Best regards. Sidnei Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEQM - Departamento de Engenharia Química e de Materiais PUC-Rio Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55) (21)3527-1243 On Mon, Jun 24, 2013 at 6:27 AM, Gabriel Landini < [hidden email] > wrote: On Monday 24 Jun 2013 03:14:08 Sidnei Paciornik wrote: > Here is a link to a pdf that explains the point. > > https://dl.dropboxusercontent. com/u/20667937/Halo%20effect. pdf I do not think this is a microscopy-only issue. Most digital images captured with a camera or scanner, if enlarged, will show some blurring around edges. There is a similar approach called Morphological Contrast or Toggle Contrast, described in Soille's book Morphological Image analysis p. 259. The procedure sets the pixel value to either Max or Min in a kernel, depending on which one is the closest to the original and so you do not need to rely on an arbitrary threshold. A macro to do this is in the Morphology zip file in my page (called Morphological_contrast.txt). However to modify this to do what you want is trivial. You do the above if the difference of max-min is above a threshold t. The original Morphological Contrast is the case when the threshold is 0. Below is the macro modified to do this. Mind the line breaks. Cheers Gabriel //---------------8<----------- ------ // Morphological_contrast_Thr // G. Landini 24/Jun/2013 // Sets the pixel value to either Max or Min, depending on which one is // the closest and above a set threshold // Similar to Toggle Contrast in Soille, Morphological Image Analysis (2004), // p. 259. // It can use operators other than Min and Max (ie Open and Close, etc) setBatchMode(true); if (bitDepth()!=24){ a=getTitle(); Dialog.create("Morphologica Contrast Thr"); Dialog.addNumber("Radius", 2); Dialog.addNumber("Threshold", 25); Dialog.show(); r=Dialog.getNumber(); t=Dialog.getNumber(); run("Duplicate...", "title=min"); run("Minimum...", "radius="+r); selectWindow(a); run("Duplicate...", "title=max"); run("Maximum...", "radius="+r); selectWindow("max"); w=getWidth(); h=getHeight(); i=0; max=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ max[i]=getPixel(x,y); i++; } } selectWindow("min"); i=0; min=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ min[i]=getPixel(x,y); i++; } } selectWindow(a); i=0; for (x=0;x<w;x++){ for (y=0;y<h;y++){ c=getPixel(x,y); if (max[i]-min[i]>t){ if((max[i]-c)<=(c-min[i])){ putPixel(x,y, max[i]); } else if ((max[i]-c)>(c-min[i])){ putPixel(x,y, min[i]); } } i++; } } updateDisplay(); selectWindow("min"); close(); selectWindow("max"); close(); } else showMessage("Error","Greyscale images only!\nConvert RGB to HSB and process\nthe Brightness channel only."); setBatchMode(false); //---------------8<----------- ------ -- ImageJ mailing list: http://imagej.nih.gov/ij/list. html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Tuesday 13 Oct 2015 21:42:39 you wrote:
> I would like to refer to the message below, from 2013, in which you sent me > the code for an edge enhancement (or delineation) algorithm in ImageJ. We > have used it several times but recently, trying to apply it to a rather > large image (18kx15k pixels), we had a strange behavior. The plugin takes > about 15 minutes running (on an i7 with 24 Gb RAM) and then apparently > finishes. However, the output image is the same as the input. > There is no error message. Hi, Can you try removing the first statement: setBatchMode(true); and try again? I guess that you might be running out of memory because that macro requires 3 images open at the same time and that might be too much for the allocated memory. Let me knows what happens. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Gabriel
Thanks for the feedback. We did remove the line but it did not help. I know it looks like a memory problem but, if so, shouldn´t there be some kind of error message? Any other suggestions? Thank you again. Sidnei Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEQM - Departamento de Engenharia Química e de Materiais PUC-Rio Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55) (21)3527-1243 On Mon, Oct 19, 2015 at 1:29 PM, Sidnei Paciornik < [hidden email] > wrote: Hi Gabriel Thanks for the feedback. We did remove the line but it did not help. I know it looks like a memory problem but, if so, shouldn´t there be some kind of error message? Any other suggestions? Thank you again. Sidnei Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEQM - Departamento de Engenharia Química e de Materiais PUC-Rio Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55) (21)3527-1243 On Wed, Oct 14, 2015 at 11:03 AM, Gabriel Landini < [hidden email] > wrote: On Tuesday 13 Oct 2015 21:42:39 you wrote: > I would like to refer to the message below, from 2013, in which you sent me > the code for an edge enhancement (or delineation) algorithm in ImageJ. We > have used it several times but recently, trying to apply it to a rather > large image (18kx15k pixels), we had a strange behavior. The plugin takes > about 15 minutes running (on an i7 with 24 Gb RAM) and then apparently > finishes. However, the output image is the same as the input. > There is no error message. Hi, Can you try removing the first statement: setBatchMode(true); and try again? I guess that you might be running out of memory because that macro requires 3 images open at the same time and that might be too much for the allocated memory. Let me knows what happens. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Gabriel
Thanks for the patience. I have just confirmed it is a memory error. Actually, I should have noticed it right away as the macro error bar shows exactly that ( OutOfMemoryError: Java heap space) . But it is still a bit confusing. The original image is 8-bit, 15591 x 18643 pixels , totalling 277 Mb of memory. I did duplicate it twice, as you suggested, and we have no problem. The computer has a total of 24 Gigabytes of RAM. We have 18 Gigabytes allocated in the Memory option for FIJI. Thus, if your code only uses 3 times the image memory size, we should be far away from our limits. However, following FIJI´s memory allocation in the Process Manager, I noticed it uses a lot of memory. Actually, it grows BEYOND the 18 gig we had allocated, what is already weird. It peaked a bit above 19 Gig. We did test the same conditions in a much faster double Xeon with 96 gigabytes of RAM and the code runs correctly. So I guess the points are: 1) Why does the code (which I attach at the end of this message) use so much memory. 2) How can FIJI use more memory that is allocated to it. Thank you again. Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEQM - Departamento de Engenharia Química e de Materiais PUC-Rio Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55) (21)3527-1243 Code follows: //setBatchMode(true); if (bitDepth()!=24){ a=getTitle(); Dialog.create(“Morphologica Contrast Thr”); Dialog.addNumber(“Radius”, 2); Dialog.addNumber(“Threshold”, 25); Dialog.show(); r=Dialog.getNumber(); t=Dialog.getNumber(); run(“Duplicate...”, “title=min”); run(“Minimum...”, “radius=”+r); selectWindow(a); run(“Duplicate...”, “title=max”); run(“Maximum...”, “radius=”+r); selectWindow(“max”); w=getWidth(); h=getHeight(); i=0; max=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ max[i]=getPixel(x,y); i++; } } selectWindow(“min”); i=0; min=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ min[i]=getPixel(x,y); i++; } } selectWindow(a); i=0; for (x=0;x<w;x++){ for (y=0;y<h;y++){ c=getPixel(x,y); if (max[i]-min[i]>t){ if((max[i]-c)<=(c-min[i])){ putPixel(x,y, max[i]); } else if ((max[i]-c)>(c-min[i])){ putPixel(x,y, min[i]); } } i++; } } updateDisplay(); selectWindow(“min”); close(); selectWindow(“max”); close(); } else showMessage(“Error”,” Greyscale images only!\nConvert RGB to HSB and process\nthe Brightness channel only.”); setBatchMode(false); //---------------8<----------- ------ On Fri, Oct 23, 2015 at 2:34 PM, Gabriel Landini < [hidden email] > wrote: On Friday 23 Oct 2015 16:01:34 you wrote: > Hi Gabriel > Thanks for the feedback. > We did remove the line but it did not help. I know it looks like a memory > problem but, if so, shouldn´t there be some kind of error message? > Any other suggestions? Open the image to process. Then duplicate it, then duplicate it again (so 3 images of the same size are open. If you run out of memory with that, then that is the cause of the problem. Can you send me the macro you are using, and tell me the size of the image (and the amount of ram allocated to IJ). Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Sidnei,
in your macro, you create two macro arrays: min=newArray(w*h) max=newArray(w*h) that, I believe, in the Macro language become arrays of Objects (Variable[]) https://github.com/imagej/imagej1/blob/master/ij/macro/Functions.java#L1350 which means that they end up on the heap of the JVM and consume about 50 + extra bytes per pixel which is a lot. Instead of Arrays, you could use the min and max images directly and use the getPixel(x,y) method to access values. You could create an image that is one pixel high and w*h pixels wide. Or have a look at a different scripting language such as Beanshell that supports primitive type arrays. The Process Manager is not a good tool to understand Java memory usage because it only shows what the JVM consumes (after some time everything), not what the Java program running on the JVM consumes. Check https://visualvm.java.net/ instead. Cheers, Stephan On Fri, 2015-10-23 at 17:45 +0000, Sidnei Paciornik wrote: > Hi Gabriel > Thanks for the patience. I have just confirmed it is a memory error. Actually, I > should have noticed it right away as the macro error bar shows exactly that ( OutOfMemoryError: Java heap space) . > But it is still a bit confusing. > The original image is 8-bit, 15591 x 18643 pixels , totalling 277 Mb of memory. I did duplicate it twice, as you suggested, and > we have no problem. > The computer has a total of 24 Gigabytes of RAM. We have 18 Gigabytes allocated > in the Memory option for FIJI. Thus, if your code only uses 3 times the image > memory size, we should be far away from our limits. > However, following FIJI´s memory allocation in the Process Manager, I noticed it > uses a lot of memory. Actually, it grows BEYOND the 18 gig we had allocated, > what is already weird. It peaked a bit above 19 Gig. > We did test the same conditions in a much faster double Xeon with 96 gigabytes > of RAM and the code runs correctly. > So I guess the points are: 1) Why does the code (which I attach at the end of this message) use so much > memory. 2) How can FIJI use more memory that is allocated to it. > Thank you again. Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital > DEQM - Departamento de Engenharia Química e de Materiais > PUC-Rio > > Rua Marquês de São Vicente 225 > Prédio Leme, Sala 501L > Gávea - Rio de Janeiro - RJ > 22451-900 - Brasil > tel: (55) (21)3527-1243 > Code follows: //setBatchMode(true); > if (bitDepth()!=24){ a=getTitle(); Dialog.create(“Morphologica Contrast Thr”); Dialog.addNumber(“Radius”, 2); Dialog.addNumber(“Threshold”, 25); Dialog.show(); r=Dialog.getNumber(); t=Dialog.getNumber(); > run(“Duplicate...”, “title=min”); run(“Minimum...”, “radius=”+r); selectWindow(a); run(“Duplicate...”, “title=max”); run(“Maximum...”, “radius=”+r); > selectWindow(“max”); w=getWidth(); h=getHeight(); i=0; max=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ max[i]=getPixel(x,y); i++; } } > > selectWindow(“min”); i=0; min=newArray(w*h); for (x=0;x<w;x++){ for (y=0;y<h;y++){ min[i]=getPixel(x,y); i++; } } > selectWindow(a); i=0; for (x=0;x<w;x++){ for (y=0;y<h;y++){ c=getPixel(x,y); if (max[i]-min[i]>t){ if((max[i]-c)<=(c-min[i])){ putPixel(x,y, max[i]); } else if ((max[i]-c)>(c-min[i])){ putPixel(x,y, min[i]); } } i++; } } updateDisplay(); selectWindow(“min”); close(); selectWindow(“max”); close(); } else showMessage(“Error”,” Greyscale images only!\nConvert RGB to HSB and process\nthe Brightness channel > only.”); > setBatchMode(false); > //---------------8<----------- ------ > > > On Fri, Oct 23, 2015 at 2:34 PM, Gabriel Landini < [hidden email] > wrote: > On Friday 23 Oct 2015 16:01:34 you wrote: > > Hi Gabriel > > Thanks for the feedback. > > We did remove the line but it did not help. I know it looks like a memory > > problem but, if so, shouldn´t there be some kind of error message? > > Any other suggestions? > > Open the image to process. Then duplicate it, then duplicate it again (so 3 > images of the same size are open. If you run out of memory with that, then > that is the cause of the problem. > > Can you send me the macro you are using, and tell me the size of the image > (and the amount of ram allocated to IJ). > Cheers > > Gabriel > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Sidnei Paciornik
On Friday 23 Oct 2015 17:45:31 Sidnei Paciornik wrote:
> Hi Gabriel > Thanks for the patience. I have just confirmed it is a memory error. Yes, it is, I can trigger the error in linux. For small images, storing the pixels as an array is not an issue, but it is with large ones, which was an oversight when I wrote that macro. Doing it one pixel at a time is not practical because the macro would need to swap the images every time you access a pixel from each of the images it uses. Instead you can compute an entire row of pixels at a time. At least this will reduce the number of swaps (which seem to take an inordinate amount of time in Java > 1.6). The attached macro does it that way and hope that runs without problems in your images. It is slower, however, so perhaps you might want to rewrite as a plugin. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html Morphological_contrast_thr.txt (1K) Download Attachment |
Free forum by Nabble | Edit this page |