Routine to analyze image line by line.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Routine to analyze image line by line.

Ethan Cohen
I have a 8bit b/w 512x512 image of tissue slide specimen.
The tissue spans all the way across the middle of the section, and is gray.


I am working on a macro to fill the image with a series of black lines  so that below the tissue (largely noise) there is black.  The tissue spans across the middle of the section, and is gray.  Magic Wand and Versatile Magic Wand do not help.

So I want to choose a threshold value of gray, let's call it 80.
Then for each vertical line selection of the image my search program starts at the bottom evaluating each pixel  and once it finds this gray value, it fills the rest of the x,y values of line i with black, 0
The idea is each x line on the slide, is evaluated from the bottom for when it turns >=threshold gray, and when it is found, it is filled black to the bottom on the same x line.

So it might something like :

Threshold = 80;  //fill a line with 0s, when a point above
for (i=0; i<512; i++) {
               for(j=0; j<512; j++); { // start at the bottom edge
               if (image(i,j ) >= Threshold){
               run("Specify...", "width=1 height=j x=i y=0");// specify line part to fill black below this value
               run("Fill", "slice");}
               }
}

Will this work?
How do I evaluate the gray value of a pixel?




Ethan Cohen, Ph.D.
Div of Biomedical Physics,
Office of Science and Engineering Labs,
FDA Center for Devices and Radiological Health
White Oak Federal Res Ctr.



--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Routine to analyze image line by line.

Ethan Cohen
getPixel(x, y) ?

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Routine to analyze image line by line.

George Patterson
Hi Ethan,
Yes, you'll need to to this line
if (getPixel(i,j ) >= Threshold){

Also, if you want the search to start at the bottom, you may need to change
the inner loop to something like the following. You should also remove the
semicolons at the end of the for loops.
for(j=511; j>=0; j--) { // start at the bottom edge

And then you would also need to change the run("Specify...) line.
That seems pretty slow. May I suggest replacing the specify and fill with
another loop to set the pixels to zero.
for(k=511; k>=j; k--) {
         setPixel(i,k,0);
}

Best of luck,
George




On Mon, Nov 16, 2020 at 11:35 AM Ethan Cohen <[hidden email]>
wrote:

> getPixel(x, y) ?
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Routine to analyze image line by line.

Kenneth R Sloan-2
In reply to this post by Ethan Cohen
I would consider using getPixel() and putPixel() to set pixels below your threshold to Black, starting at the bottom, and ending when you find the first pixel over the threshold.
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Routine to analyze image line by line.

olivier-2
In reply to this post by Ethan Cohen
Maybe I missed something but duplicate image > setThreshold to 80 > convert to mask > fill holes > erode > doWand(256, 256) > create selection.
Return to your original image > restore selection > doWand(1,1) > fill black.
I have not your image to write the macro and test it.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html