What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Histogram Pixel Area Problem


researchdude

Member
Messages
6
Likes
0
Hello,

For a research project, I am calculating the area of the cytosol of a cell by finding the total cell area and subtracting the total nuclear area. I have been using the lasso tool to select the boundaries and then the histogram to measure the total pixels in that selection area. Proportionately, the nuclear pixel area should always be smaller than the total cell area since the nucleus is inside that cell. Most of my measurements have been accurate, but I started to run into the problem in which occasionally the nuclear pixel area is larger the total cell area. This does not make sense, which means that Pixel # that the histogram records must not actually be counting every pixel. I have tried to do some reading online and it sounds like the histogram is made based on different color intensities. If that were the case, that histogram pixel count is not the total area of the selection but rather only the pixel count that is being used to calculate the histogram.

I have tried changing the Channels from grayscale to RGB, etc. to see if that might use more of the pixels but there is no difference. Can you someone please explain the difference in these measurements and how can I make sure that the histogram counts every pixel?

Also, once I have that issue figured out, to convert my pixel count to a cell area, do I use the equation A=P/s^2?
A=real cell area
P=pixel count
S=linear pixel/cm. I have a bar scale from the microscope on the bottom of each image, thus I can accurately find this variable. I would have to square it since I need the area.

Does that look correct?

Thanks!
 
Assuming you haven't forgotten to check Selected Area from the dropdown for the measurements that don't jibe, it sounds like this would a question for Adobe regarding their computational methods.
 
What do you mean by assuming I chose Selected Area? As of now, I just make the selection with the lasso tool and the histogram pixel # changes accordingly everytime I make a new selection. I'm not sure what you're referring to? Thanks again.

Currently, the histogram reads 192,500 pixs for the entire image. When I make a small selection with the lasso tool, the pixel account goes above 300,000 pixs. Something is obviously set up wrong with the histogram options....any idea?
 
Last edited:
thats a pretty steep question I would follow Hawkeyes advise " it sounds like this would a question for Adobe regarding their computational methods. " but if you do happen to find your answer elsewhere an update would be appreciated... Hopefully another member can help .. Good luck.
 
Hello,

Also, once I have that issue figured out, to convert my pixel count to a cell area, do I use the equation A=P/s^2?
A=real cell area
P=pixel count
S=linear pixel/cm. I have a bar scale from the microscope on the bottom of each image, thus I can accurately find this variable. I would have to square it since I need the area.

Does that look correct?

Thanks!

No it doesn't, you can not calculate an area unless you incorporate the resolution of your document. 300PPI = 1 Inch 200PPI = 1inch etc. assuming pixels/inch.
Also, S=linear pixel/cm
When you go to view - image size does the resolution show pixels/inch or pixels/cm

Also the selection no matter how its made should be the total pixels selected.
Should be the same for all channels.
Code:
var cnt =0;
histogram = activeDocument.channels["Red"].histogram; 
for (i = 0; i <= 255; i++) { 
 cnt += histogram[i];
} 
alert(cnt);
Should be the same as what is shown in the histogram.
 
Okay, I'll let you know about the histogram calculation once I find out.

As for the rest of the equation, does my equation make sense to convert the total pixels of the selection into centimeters?

A=P/S^2
A=real area
P=total pixel number in selection
S=pixel/centimeter, measured from a bar scale that came with the picture

I'm a bit confused on the S^2 part. When you square that, woudn't it give you pixels^2/cm^2? We want A=cm^2, but once we cross out all the units, we are left with A=pixel*cm^2 since P=pixel and not pixel^2. People on another forum were claiming that equation works, but it looks flawed to me and the post is 10 years old so I can't ask on there ha. Your thoughts?
 
Actually, the resolution should not matter because these pictures are taken from an electron microscope and it already displays a bar scale of the real life size in micrometers. All I have to do is go to Edit/Preferences/Units and Ruler and set the Ruler to pixels. From there, I can draw a line using the ruler tool and line it up perfectly with the bar scale. From there, I now have a pixel/micrometer conversion. :) From the pixel count of the histogram, I should be able to convert it to micrometers using that pixel/micrometer conversion. I just want to make sure the pixel units cancel out correctly. That's what I am asking.

You were referring to calculating the printed area if I wanted to print out the image on paper. For that, you need to use the resolution. I am calculating the the surface area of the real-life cells. This is totally different than the printed area on paper.

Also, I figured out what was wrong with the histograms. Usually the measurements were accurate, but the random times were because of the cached histogram data. Photoshop tells you when you should uncache the histogram data. All I have to do is hit refresh and then it adjusts everything accordingly. lol, I just wasn't aware you had to refresh anything so I never noticed the little exclamation point in the top corner of the histogram.

No it doesn't, you can not calculate an area unless you incorporate the resolution of your document. 300PPI = 1 Inch 200PPI = 1inch etc. assuming pixels/inch.
Also, S=linear pixel/cm
When you go to view - image size does the resolution show pixels/inch or pixels/cm

Also the selection no matter how its made should be the total pixels selected.
Should be the same for all channels.
Code:
var cnt =0;
histogram = activeDocument.channels["Red"].histogram; 
for (i = 0; i <= 255; i++) { 
 cnt += histogram[i];
} 
alert(cnt);
Should be the same as what is shown in the histogram.
 
Last edited:
Phheeewwwwwwwwww, my brain hurts just trying to read and understand the math equation.
Hope you find your answers mate.
 
Histograms are a visual representation...
I would consider them far from accurate for your purposes...
why not just enlarge to 1000% and count accurately...

select, isolate on layers, and make large prints... for exact counting...
 
Thats fine IF you are working the size out from a print-out, when working on data resolution is required, the picture requires calibrating as well! Counting pixels is totally meaningless unless you have some means of reference! The Only thing you can do without resolution is work out the percentage of pixels to the whole document.

If there is a scale on the picture, have you resized the picture to reflect the size of the scale if not your area calculations are meaningless?
IE if you measure the scale on the picture in pixels does it give you the same size as shown on the scale, are there any perspective/barrel distorsion parameters to be taken into account?
 
Awesome! I have everything figured out.


So, for the histogram total pixel issue, all I have to do is make sure I uncache the histogram. Photoshop tells you when you need to with an exclamation point in the corner. If you don't, it may mess up the new histogram. I randomly figured this out from reading on a random forum.



As for the Record Measurements tool, I don't think that is in normal photoshop BUT the histogram pixels is the same number. I confirmed this by using CS5 Extended at work and both histogram pixels and Record Measurement area are the same values. This is even better news for me because it confirms that the hsitogram value IS the area of the selection. This allows me to use my conversion to micrometers using the barscale on the image PERFECTLY.


Thanks for all your help!
 
I came here googling the same problem. It seems the pixel counter tool breaks down at higher numbers. It says 100000 for a blank 100x100 image, 200000 for a 200x1000 image, 300000 for 300x1000, but 100000 for a 400x100000 image. :frown: And for images with millions of pixels in them it never seems to show more than six digits.

But there is a workaround. If the area being selected has the same width and height as the canvas, then the ratio should be correct. So here's what you do.

  1. Select the area you want to measure.
  2. Go to Window -> Histogram. Take a note of the number of pixels it says in the bottom-left of this panel*.
  3. Go to Image -> Crop, to crop the image around your selection. Then deselect it (Select -> Deselect). Again, take a note of the pixel count in the histogram panel.**
  4. Divide the first number by the second to get a number between 0 and 1.
  5. Now go to Image -> Image Size, and measure the actual number of pixels in the rectangle you just cropped by multiplying the width and the height together.
  6. Multiply this with the number from the previous step. And you'll have the number of pixels in your selection.
  7. to convert this to square centimetres or square inches, divide by the resolution twice. Remember the original area is effectively measured in 'square pixels' if we consider pixels to be a unit of length.

*If you can't see it, click HERE: 2Qiiy.png and click extended view.
 

Back
Top