Re: Leveling Image
Posted by Gabriel Landini on Aug 23, 2011; 1:49pm
URL: http://imagej.273.s1.nabble.com/Leveling-Image-tp3683357p3683358.html
Here is the idea I was thinking of.
The first macro loads the Lena image and creates random offsets for the scan
lines to simulate a scan with artifacts.
//-----------8<---------------
run("Lena (68K)");
setBatchMode(true);
a="_test_";
run("Duplicate...", "title="+a);
run("8-bit");
run("Reslice [/]...", "output=1.000 start=Top");
selectWindow("Reslice of "+a);
for(i=1;i<=nSlices;i++){
setSlice(i);
r=random()*32;
run("Add...", "value="+r+" slice");
}
run("Reslice [/]...", "output=1.000 start=Top");
setBatchMode(false);
//-----------8<---------------
This other macro creates a ROI over the more or less constant background (the
clear part on the left of the image) and compensates for a difference between
the average background and that of the individual lines.
//-----------8<---------------
makeRectangle(42, 0, 13, 512);// Lena's background
getRawStatistics(nPixels, mean);
run("Select None");
print(mean);
for (y=0;y<512;y++){
tot=0;
for (x=42;x<55;x++){
tot=tot+getPixel(x,y);
}
tot=tot/13;
offset=mean-tot;
//print(offset);
for (x=0;x<512;x++)
putPixel(x, y, getPixel(x,y)+offset);
}
updateDisplay()
//-----------8<---------------
This works well if the background is constant. In the Lena image, the
background varies slightly so the result has a bright line relatively visible
because the background has a darker pixels in that particular region.
The problem is that the example given earlier does not have such a constant
background region for reference.
Cheers
Gabriel