Calculation of positive pixels

Hi!
I am new at imagej, and have some issues
I need to calculate the positive (brown) area over total stained area in percents. The black holes are removed by me in imagej and should not be counted as a part of the area.
image
I ve used color threshold to select the brown areas

image

Measurement set
image

and as a analyze result i get only number of selected pixels.
What am I doing wrong?
Thanks in advance

Good day,

what other do you expect to get than the number of “brown” pixels?

If you know the distance of the pixels in your image in physical units, you can use the ImageJ scale feature to get areas in physical units otherwise you get it in pixels^2.

If your problem actually is a different one, you need to explain it more clearly.

Regards

Herbie

PS:
I hope your original images are not JPG-compressed (which is a no-no for any kind of scientific image analysis).

1 Like

What i wanted to do, is to get a fraction: brown pixels/all pixels in the ROI. ROI is everything but these black areas. The problem is that currently black areas are calculated as a part of ROI.

My current updated solution is that I convert the image to 32bit image, use threshold to get brown (dark) pixels, then use the same threshold to get all the pixels except the black ones, and then simply divide these numbers manually.
Seems a little bit primitive, but works fine

Are there any advanced solutions? As I understand, ImageJ cannot make a transparent background?
What is the best format for scientific image analysis? TIFF?

My current updated solution is that I convert the image to 32bit image

I agree that your approach is perfectly ok.
What else do you want?

Seems a little bit primitive, but works fine

???

Are there any advanced solutions?

What do you mean?
Why aren’t you happy with the results you get?

What is the best format for scientific image analysis? TIFF?

Yes TIFF, especially if you work with ImageJ.
Please note that converting a JPG-compressed image to TIFF-format doesn’t make sense, because JPG-compression is lossy and introduces artifacts that can’t be removed. If an image ever was JPG-compressed it will suffer from these artifacts independent of what format you apply to it later!

Regards

Herbie

1 Like

Thanks for Your answer!
I thought I can use NaN values to mask out these black areass.
But if you think my solution is ok- I will stick to it :slight_smile:
Happy New Year!

I thought I can use NaN values to mask out these black areass.

I thought that you did just that by converting the image to 32bit and setting the black areas to NaN?

I’m not perfectly clear what you finally did.

Regards

Herbie

:slight_smile:

  1. I have a png image.
  2. Convert it to 32 bit
  3. remove the area i don`t need
  4. using threshold, get all the brown (dark grey) pixels

    the area is 102179
  5. Get the total area

    625259
  6. 102179/626259= 16,3%

What you are doing works fine.

I would consider getting the total area using ROIs. Rather than blacking out the areas as in your first image, add all the areas you want to exclude to the ROI manager:
https://imagej.nih.gov/ij/docs/menus/analyze.html#manager
The keyboard shortcut to add an area to the ROI manager is Control-t.

Once you have added all the individual exclusion ROIs to the ROI manager, combine them together by

  1. Selecting all the ROIs in the ROI manager
  2. Click on More >>
  3. Select OR (Combine)
  4. Add this combined ROI to the ROI manager
  5. Selecting the combined ROI, go to Edit -> Selection -> Make Inverse
  6. Add the inverted ROI to the ROI manager. This is your true region of interest.

You can then use the Measure feature to obtain the area of the ROI. Similarly you can use the color threshold tool to select the brown pixels and then also add that to the ROI manager.

My concern is that in converting your image from RGB to 32-bit real, you convert your color image to a gray scale image. You might then have less flexibility in selecting the truly brown pixels in the gray scale image than you might have in the color image. By using ROIs, you do not need convert your image to gray scale.

What is the best format for scientific image analysis? TIFF?

TIFF generally can be a mixed bag since it really is more of a container than a format itself. One could use lossy JPEG compression with TIFFs which would not be appropriate for scientific image analysis.

I would first consider the format of your raw data as well as the associated metadata. Make sure to preserve the raw data and metadata as much as possible. If you are acquiring images, I would first save the image in the native vendor format to preserve as much information as possible. Consider then exporting that format to OME-TIFF: https://docs.openmicroscopy.org/ome-model/5.6.3/ome-tiff/ which you could do via ImageJ using the Bioformats plugin: https://www.openmicroscopy.org/bio-formats/

Markkitt, Herbie
Thanks a lot!
It is a good argument that I lose some of the brown pixels in my B&W image; but using threshold seems to be a little faster.
I will need to process a bigger amount of pics to make a decision :slight_smile:
Thanks again!

that I lose some of the brown pixels in my B&W image

Not necessarily, it depends on how you do it.
I’d try an appropriate color-space, e.g. Lab or CMYK and use the best channel. You may also split the RGB into its channels…

In any case you should not manually set thresholds. Always use one of the Automatic Threshold schemes and stay with this scheme for all images of one class (staining etc.). Using Automatic Threshold schemes allows for generalization and reproducebility which means best practice.

Regards

Herbie

I ve tried to use a LAB stack
It is actually quite good, can easily separate brown and blue
image
But I don t know how to get pixel number from the red area :slight_smile:
It is a valid point that I should use auto threshold.
I ve tried all the standard types
The problem is, all of these mark to much of a tissue on auto threshold
image

Here is what I get from your previous example image and exclusion rectangle:
Results
(Data obtained with my updated macro.)

But I don t know how to get pixel number from the red area

What is different when compared to your previous processing?
Could you provide the original image and tell us what you like to obtain?

Regards

Herbie

1 Like

@Pisakita you wrote:

I need to calculate the positive (brown) area over total stained area in percents

What i wanted to do, is to get a fraction: brown pixels/all pixels in the ROI.

It seems to me those aren’t (necessarily) the same, depending on how you define ‘stained area’.

In any case, I think you might want Analyze → Set Measurements… and turn on Area fraction then use Analyze → Measure in your region of interest.

1 Like

With the b*-channel from Lab and the “Yen”-threshold scheme I get an area of 23167 pixels^2 from the provided screenshot.

Does this make sense?

Regards

Herbie

1 Like

These should be the same :slight_smile:
Stained area e. everything except the black one
Positive area= brown.

Herbie,
for example, I have a picture


ROI is

Need to measure brown tissue to total.

I Make a lab stack
Using threshold, measure the brown one


I also need the total area of the sample. But as u can see from the screenshot,
areas with different % have the same “area” values.
I don`t understand, why.
I have a solution, I can measure the total are before converting to lab stack. But still, It is an additional movement.

summa summarum I now have different solutions, need to pick one with a good reproducebility

PS. I am currently reading modern pathology journal; it has quite high impact factor, still nobody describes the process of imagej measurements

I mean… stained area could mean stained blue or brown (in which case the ImmunoRatio plugin for ImageJ might be relevant), or it could mean ‘the area I’ve selected that could potentially be stained, even if not all of it is’.

The second option is what I think you mean, based on your other posts. What you appear to be measuring is the proportion of selected tissue that is stained brown. But it isn’t the proportion of stained pixels that are brown, because many pixels inside your ROI aren’t stained… in other words, it looks like you’re normalizing by stromal area, and not by hematoxylin + DAB stained area.

In any case, please do check out the Area fraction as I mentioned above. No need for a separate macro. It should give the percentage of the current ROI that is thresholded (i.e. shown as red).

(PS. I wrote QuPath, which I can see you’re using from your screenshots… there’s also a QuPath Google Group here)

2 Likes
  1. start with your “imagej1a.png”
  2. convert it to Lab
  3. in channel “L”, select both black areas with the Wand-tool
  4. go to channel “b*” and set value to NaN
  5. run the following ImageJ-macro:
run("Select None");
run("Measure");
setAutoThreshold("Yen dark");
run("NaN Background");
run("Measure");
setResult("% Area", nResults-2, 100);
setResult("% Area", nResults-1, 100*getResult("Area", nResults-1)/getResult("Area", nResults-2));

This gives me:

Area____%Area
165308__100,00
33309____20,15 (brown)
———————————————————

I am currently reading modern pathology journal; it has quite high impact factor, still nobody describes the process of imagej measurements

Can’t help.
Maybe “modern” science, lack of time, bad habits, incompetence, no supervision, you name it …

Good luck

Herbie

1 Like

Oh, now I understand your point. Yes, I am actually normalizing by stromal area:)
BTW, QuPath is great

Final verdict.
I export image from qupath to imageJ
Remove all the unnecessary areas leaving only ROI
Convert to LAB stack
In L* create black area selection. Invert selection- now ROI is selected.
Autothreshold in b*. using Li- better, in comparison with Yen. Dark background.
Measurements “area”, “fraction”, “NaN”
Get the result
Actually same thing, as in Herbieˇs macro
Day well spent :wink:
Thank you, guys!

Hi Pisakita,
Image > Type > 32Bit, then Edit > Invert, then Image > Adjust > Threshold, then Analyze > Analyze Particles. All the results you could want is presented and made as ROIs should you want to play with it a little.
Bob

1 Like