Automatically select "white" images (microscopic images showing only background) from stack and delete

fiji
imagej

#1

Hi, I am analysing microscopic images. Since the structures I am analysing are very big, the microscope automatically makes multiple adjoining images. Thereby also a lot of “white” images are generated, which only show the background, not the structure I am interested in. Is it somehow possible to automatically select these images in order to delete them afterwards? At the moment I am selecting the “white images” by hand, which is very time consuming.

Do you have any ideas?
Thanks a lot


#2

Depending on the type of image you are dealing with, you could attempt to find if there is any tissue in the image by computing a threshold for the background (e.g. via the saturation in HSV space) and comparing the area of the thresholded phase to the area of the image. If it is close to the image size, then assume that it is mostly background.


#3

My problem is that I want to automatically select and remove specific images / slices from a stack or batch of images.

These images / slices I want to automatically exclude are all white. At the moment I have to look at every image / slice of my stack and remove the white ones by hand.

A function solving my problem could for example be to create a sub stack, which only contains pictures with a certain amount of pixels that are different from white or only such images / slices containing contrasts within certain thresholds. A idea is also to select one of the white images by hand and let imageJ or Fiji find and select all of those images / slices which are identical or similar and remove them all at ones.

But I have no idea how I could do this with imageJ or Fiji

Thanks for suggestions and help!


#4

Can you upload a sample image or stack with examples of what you are after?


#5

Good day Jessica,

it appears as if the slices in question are not really “white”, i.e. they may contain pixels with values ≠ 255.

So please post at least two slices of a stack:

  1. A slice with a typical structure
  2. A slice that you judge being “white”

Please post the slice images in their original RAW- or TIF-file format.
No JPG-format though, because JPG introduces artifacts!
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)
You may also post images as ZIP-archives or make them accessible via a dropbox-like service.

The task to eliminate the slices in question from stacks in an automatic fashion can be solved if we know exactly how the “white” slices really look like and how they differ from the slices with structured contents.

To separate both types of slices can be rather easy or may need a more adavnaced analysis concerning the degree of structure. Without seeing typical slices we can’t telll you what to do.

Regards

Herbie


#6

Dear Herbie,
thanks a lot for your suggestioins, you are absolutelly right!

Here are two example pictures. One lacks structures I am interested in, the other one contains structures. Normally I adjust brightness and contrast when I analyse them, then they appear white, but these are the original ones.

When taking these pictures I select a certain area on a microscopic slide and then I let the machine take the Images with a certain magnification. This is something you would also do as a first step, if you want to do a Multiple Image Alignment. Therefore I get a lot of These “empty” Images which I would like to exclude without looking at every picture in order to remove it by hand.


#7


#8

Thanks for posting the images.

The “white” image shows a noisy gray value of Mean ≈ 125 and StdDev ≈ 17.7;

My first attempt would be to eliminate images showing typical statistical features.
With an ImageJ-macro this should be possible.

Loop through the slices of the stack and for every slice:

  1. Get the statistical features
  2. Compare the features to those of a “white” prototype
  3. Decide whether to keep or eliminate

One may start with simple statistical features such as the StdDev, Skewness, and Kurtosis.

I shall provide you with a macro-template that does this.

Please stay tuned

Herbie


#9

Hello Herbie,

thank you so much for your effort, I really appreciate that!

Best regards
Jessica


#10

Jessica,

here is a sample stack with 12 slices as a ZIP-archive
sampleStack.zip (13.0 MB)
that (after un-zipping it) you may use to test the following ImageJ-macro:

// imagej-macro "stackClean" (Herbie G., 06. Dec. 2018)
requires( "1.52i" );
sdevThr=5.0;
kurtThr=30.0;
setBatchMode(true);
run("Duplicate...", "title=temp duplicate");
i=1;
do { 
   setSlice(i);
   List.setMeasurements;
   sd=List.getValue("StdDev");
   krt=List.getValue("Kurt");
   if (sd<sdevThr && krt>kurtThr ) run("Delete Slice"); else i++;
} while (i<=nSlices);
setBatchMode(false);
setSlice(1);
exit();
// imagej-macro "stackClean" (Herbie G., 06. Dec. 2018)

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it with the sample stack open in ImageJ.

The resulting stack has 8 slices, i.e. 4 “white” slices have been eliminated from the original sample stack.

Please note that the macro checks for two statistical values, the Standard Deviation and the Kurtosis. The values are checked versus the respective threshold values defined at the beginning of the macro. For the sample stack a “white” slice is detected and deleted
if its sd < 5 and if its krt > 30;

You may choose the threshold values to fit your needs.

Just measure “white” and structured slices of your stack with:
screenShot

The threshold values should be between the values you get for the “white” and a typical structured slice.

HTH

Herbie


#11

Herbie,

This is great, thanks a lot for your help!
I will try out the macro with a couple of my stacks and tell you how it works.

cheers
Jessica


#12

Jessica,

in any case please try the macro with the provided sample stack first and report back if it works as expected!

Regards

Herbie


#13

Yes, it worked excellent. Therefore I will try it with some of my “real” stacks :smiley:


#14

Just a hint:

Perhaps youu try with the Standard Deviationa alone:

Replace these two code lines

   krt=List.getValue("Kurt");
   if (sd<sdevThr && krt>kurtThr ) run("Delete Slice"); else i++;

by this line

   if (sd<sdevThr) run("Delete Slice"); else i++;

Regards

Herbie


#15

Another approach with the Background subtraction, which works with your stack. Adjust the mean threshold (I used 5 here) to suit your needs.

title1 = getTitle();
run("Duplicate...", "title=temp duplicate");
run("Subtract Background...", "rolling=50 stack");
n = nSlices;
for(i=n; i>0; i--) {
	setSlice(i);
	List.setMeasurements;
	avg=List.getValue("Mean");
	if(avg < 5) {
		selectImage(title1);
		setSlice(i);
		run("Delete Slice");
		selectImage("temp");
	}
}
close();
setSlice(1);

Ved