Re: Edge Enhancement

Posted by Gabriel Landini on
URL: http://imagej.273.s1.nabble.com/Edge-Enhancement-tp5003576p5003594.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