Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how can we count the number of pixel in object

Subject: how can we count the number of pixel in object

From: Jo Li

Date: 25 Aug, 2010 12:55:08

Message: 1 of 25

hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..

Subject: how can we count the number of pixel in object

From: Walter Roberson

Date: 25 Aug, 2010 14:14:32

Message: 2 of 25

On 25/08/10 7:55 AM, Jo Li wrote:
> hi..i want to know how we can count the total pixel in object (the total
> pixel between two dots)..
> for example: i want to know the total pixel in human height from the
> photo (from the top of the head to the bottom of the feet in a photo)..

Has the problem changed since the last time you posted a very similar
question and I asked you to clarify how you wanted to take the measurement?

Subject: how can we count the number of pixel in object

From: Sean

Date: 25 Aug, 2010 14:19:19

Message: 3 of 25

"Jo Li" <de_lynx@hotmail.com> wrote in message <i533rc$3gg$1@fred.mathworks.com>...
> hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
> for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..

If you have the Image Processing Toolbox:
help bwconncomp
help regionprops

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 25 Aug, 2010 14:41:19

Message: 4 of 25

On Aug 25, 8:55 am, "Jo Li" <de_l...@hotmail.com> wrote:
> hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
> for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..

-------------------------------------------------------------------------------------------
Here's a snippet of code you can adapt. It came from a button
callback where the user manually draws a line from one point to
another on the image, and the distance is calculated. Note: this
will not run by itself since it was pulled from some other code. You
will need to ADAPT it, in other words, just pull out the lines of code
that you need, notably, the improfile() line.

% Open a temporary full-screen figure if requested.
enlargeForDrawing = get(handles.chkEnlargeForDrawing, 'value');
axes(handles.axesImage);
if enlargeForDrawing
hImage = findobj(gca,'Type','image');
imageInside = get(hImage, 'CData');
hTemp = figure;
hImage2 = imshow(imageInside, []);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
end

txtInfo = sprintf('Left click to anchor first endpoint of line.
\nDouble left click to anchor second endpoint of line.');
set(handles.txtInfo, 'string', txtInfo);

[cx,cy, rgbValues, xi,yi] = improfile(1000);
if enlargeForDrawing
% Close the temporary figure if needed.
close(hTemp);
end

% Switch focus back the the image on the main screen.
axes(handles.axesImage);
% rgbValues is 1000x1x3. Call Squeeze to get rid of the singleton
dimension and make it 1000x3.
rgbValues = squeeze(rgbValues);
distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
distanceInRealUnits = distanceInPixels *
calibration.distancePerPixel;

if length(xi) < 2 then
return;
end

Subject: how can we count the number of pixel in object

From: Jo Li

Date: 26 Aug, 2010 16:24:09

Message: 5 of 25

no walter..it's the same..
i'm having a trouble to find my last post yesterday..
i had read your post before now..
i want to know the total pixel in the straight line from the top of the head to the toe..
thx for your help..

Subject: how can we count the number of pixel in object

From: Walter Roberson

Date: 26 Aug, 2010 16:58:29

Message: 6 of 25

On 26/08/10 11:24 AM, Jo Li wrote:
> no walter..it's the same..
> i'm having a trouble to find my last post yesterday..
> i had read your post before now..
> i want to know the total pixel in the straight line from the top of the
> head to the toe..

Straight line -- so does that mean that if the top of the head is not
directly over the toe, that the straight line you want to consider is
the one on the angle? If so should the total pixel be counted or should
allowance be made for the fact that at (say) 45 degrees, 1 visible pixel
would be sqrt(2) distance units?

If the arrangement were,

H
X
T

then would you be looking for the answer 1, since there is only one
pixel (the X) *in* the line, with the H and T being at the boundaries
rather than *in* the line?

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 26 Aug, 2010 18:20:04

Message: 7 of 25

On Aug 26, 12:24 pm, "Jo Li" <de_l...@hotmail.com> wrote:
> no walter..it's the same..
> i'm having a trouble to find my last post yesterday..
> i had read your post before now..
> i want to know the total pixel in the straight line from the top of the head to the toe..
> thx for your help..
----------------------------------------------------------------------------------------------------------------------------------------
Jo Li:
Were you unable to adapt the code I gave you? Well I did in a few
minutes.
Try this demo to hand-draw the distance and have it report the
distance and plot the intensity along the line:

% By Image Analyst
% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in standard MATLAB gray scale demo image.
% imageArray = imread('football.jpg');
imageArray = imread('cameraman.tif');
[rows columns numberOfColorBands] = size(imageArray);
subplot(2, 1, 1);
imshow(imageArray, []);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

userPrompt = sprintf('Left click to anchor first endpoint of line.
\nDouble left click to anchor second endpoint of line.');
uiwait(msgbox(userPrompt));
[cx,cy, rgbValues, xi,yi] = improfile(1000);
% Draw the line on the image.
hold on;
line(cx, cy, 'LineWidth', 3, 'Color', 'r');
% Note: if the image is monochrome, rgbValues will be just Nx1, not
Nx3.
if numberOfColorBands > 1
% rgbValues is 1000x1x3. Call Squeeze to get rid of the singleton
dimension and make it 1000x3.
rgbValues = squeeze(rgbValues);
end
subplot(2, 1, 2);
plot(rgbValues);
title('Intensity Profile', 'FontSize', fontSize);
xlabel('Distance Along Line', 'FontSize', fontSize);
ylabel('Intensity', 'FontSize', fontSize);
distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
message = sprintf('The distance is %.2f pixels.', distanceInPixels);
uiwait(msgbox(message));

Subject: how can we count the number of pixel in object

From: Jo Li

Date: 28 Aug, 2010 10:20:27

Message: 8 of 25

@image analist:
i'm new to this matlab software..>.<..
i've try the code you gave..
the image shows up but the part that i don't understand is how can i draw the line..i used the improfile command and draw the lines on the picture and it automatically plot the pixel, is that how it works??
thx for your help..

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 28 Aug, 2010 13:00:48

Message: 9 of 25

Yes. That's what it does. Plus it tells you the distance.

Subject: how can we count the number of pixel in object

From: Jo Li

Date: 29 Aug, 2010 06:35:04

Message: 10 of 25

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9f74a2da-209e-47de-ac8c-7a1564bb29df@l20g2000yqe.googlegroups.com>...
> Yes. That's what it does. Plus it tells you the distance.

thx..
how about if i want the result can be directly show in one box instead of plot..what should i change from the code that you gave??

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 29 Aug, 2010 13:37:06

Message: 11 of 25

On Aug 29, 2:35 am, "Jo Li" <de_l...@hotmail.com> wrote:
> how about if i want the result can be directly show in one box instead of plot..what should i change from the code that you gave??
----------------------------------------------------------------------------------
I don't know what you're saying. Please define "one box." Are you
wanting text values of the profile in an edit text box? Are you
wanting the distance to be reported in a message box? I'm not sure.

Subject: how can we count the number of pixel in object

From: Jo Li

Date: 31 Aug, 2010 14:09:27

Message: 12 of 25

hmm..the second one..
i want the distance to be reported in a message box..

Subject: how can we count the number of pixel in object

From: Image Analyst

Date: 31 Aug, 2010 15:33:06

Message: 13 of 25

Well it does that. So I'm not sure where you're confused. Did you see the last two lines:
message = sprintf('The distance is %.2f pixels.', distanceInPixels);
uiwait(msgbox(message));
This puts your number into a string and then shows that string to the user in a message box. Isn't that what you wanted?

Subject: how can we count the number of pixel in object

From: Jo Li

Date: 2 Sep, 2010 06:35:06

Message: 14 of 25

hmm..i noticed that..the result come out in the message box..
exactly i want the result to be list in the box some kind like the excel spreadsheet..and when i finish with one picture, i can move to the other picture and difine a new distance from a new picture..then after about, for example, 30 picture, all of the distance can be shown at one table..is it possible to do that??

Subject: how can we count the number of pixel in object

From: Ömer KAYA

Date: 2 Sep, 2010 07:16:05

Message: 15 of 25

"Jo Li" <de_lynx@hotmail.com> wrote in message <i533rc$3gg$1@fred.mathworks.com>...
> hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
> for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..

help imfinfo...

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 2 Sep, 2010 10:08:29

Message: 16 of 25

On Sep 2, 3:16 am, "Ömer KAYA" <e170...@metu.edu.tr> wrote:
> "Jo Li" <de_l...@hotmail.com> wrote in message <i533rc$3g...@fred.mathworks.com>...
> > hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
> > for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..
>
> help imfinfo...

-------------------------------------------------------------------
Total nonsense. imfinfo won't determine that. No way, no how (unless
somebody stuffed it into some kind of metadata already). You must
have been thinking of some other thread when you replied.

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 2 Sep, 2010 10:10:07

Message: 17 of 25

On Sep 2, 2:35 am, "Jo Li" <de_l...@hotmail.com> wrote:
> hmm..i noticed that..the result come out in the message box..
> exactly i want the result to be list in the box some kind like the excel spreadsheet..and when i finish with one picture, i can move to the other picture and difine a new distance from a new picture..then after about, for example, 30 picture, all of the distance can be shown at one table..is it possible to do that??

--------------------------------------------------------------------------------------
Do you mean like a MATLAB uitable grad control, or do you actually
want it to be in a workbook (if so, use xlswrite)?

Subject: how can we count the number of pixel in object

From: Ömer KAYA

Date: 2 Sep, 2010 10:23:24

Message: 18 of 25

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4a5f042f-6ed8-4f7c-b585-12800528a550@n3g2000yqb.googlegroups.com>...
> On Sep 2, 3:16 am, "Ömer KAYA" <e170...@metu.edu.tr> wrote:
> > "Jo Li" <de_l...@hotmail.com> wrote in message <i533rc$3g...@fred.mathworks.com>...
> > > hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
> > > for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..
> >
> > help imfinfo...
>
> -------------------------------------------------------------------
> Total nonsense. imfinfo won't determine that. No way, no how (unless
> somebody stuffed it into some kind of metadata already). You must
> have been thinking of some other thread when you replied.

Hi;

imfinfo give you the images pixels as lenght of how much pixels does this image has;
if you know the pixel distance then you can multiply it with the side lenght of one image;
example 12340 pixels x 6 nm = ...
now you have the lenght in meters (nm) which one side of the image;
now is the tricky part;
the focal lenght: image acusition distance; google: Metric Image Acusition;
gives you the formulas which to determine the 2D area and also the lenght of a shape in 2D plane if you wanna go with 3D the image has to be either obligue or stereo;

does this makes sense?

have a nice day...
Ömer KAYA
Middle East Technical Universty

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 2 Sep, 2010 10:35:28

Message: 19 of 25

On Sep 2, 6:23 am, "Ömer KAYA" <e170...@metu.edu.tr> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <4a5f042f-6ed8-4f7c-b585-12800528a...@n3g2000yqb.googlegroups.com>...
> > On Sep 2, 3:16 am, "Ömer KAYA" <e170...@metu.edu.tr> wrote:
> > > "Jo Li" <de_l...@hotmail.com> wrote in message <i533rc$3g...@fred.mathworks.com>...
> > > > hi..i want to know how we can count the total pixel in object (the total pixel between two dots)..
> > > > for example: i want to know the total pixel in human height from the photo (from the top of the head to the bottom of the feet in a photo)..
>
> > > help imfinfo...
>
> > -------------------------------------------------------------------
> > Total nonsense.  imfinfo won't determine that.  No way, no how (unless
> > somebody stuffed it into some kind of metadata already).  You must
> > have been thinking of some other thread when you replied.
>
> Hi;
>
> imfinfo give you the images pixels as lenght of how much pixels does this image has;
> if you know the pixel distance then you can multiply it with the side lenght of one image;
> example 12340 pixels x 6 nm = ...
> now you have the lenght in meters (nm) which one side of the image;
> now is the tricky part;
> the focal lenght: image acusition distance; google: Metric Image Acusition;
> gives you the formulas which to determine the 2D area and also the lenght of a shape in 2D plane if you wanna go with 3D the image has to be either obligue or stereo;
>
> does this makes sense?
>
> have a nice day...
> Ömer KAYA
> Middle East Technical Universty
---------------------------------------------------------------------------------------
That will let you establish a spatial calibration for your image (how
many pixels per cm), but it will not tell you the height of a man
standing in the photo, unless he's taking up the entire height of the
photo, which is unlikely. She wanted to measure the height of a man
taking up (presumably) less than the total height of the photo.
-ImageAnalyst

Subject: how can we count the number of pixel in object

From: Ömer KAYA

Date: 2 Sep, 2010 10:52:22

Message: 20 of 25


> That will let you establish a spatial calibration for your image (how
> many pixels per cm), but it will not tell you the height of a man
> standing in the photo, unless he's taking up the entire height of the
> photo, which is unlikely. She wanted to measure the height of a man
> taking up (presumably) less than the total height of the photo.
> -ImageAnalyst

Hi;
it does not gives you the calibration it is another part;

what i meant is it can give you the exact height of an object (human, bowl, anything) in reference of the pixels measured as pixels and then turned into meters.

This way you can achieve the height anything depending on the pixels without any close range photogrammetry formulas you can not achieve a result.

ı do not think that Matlab deals with these...

so just dig in;

Topics to look for is:

one image rectification,
photomodeler tutorials,
close range photogrammetry - object measurement...

photomodeler has some great streaming tutorials in this purpose; which you can get an understanding of what do i mean...

Ömer KAYA
METU

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 2 Sep, 2010 14:31:10

Message: 21 of 25

Ömer KAYA:
OK, fine. But the whole point is that she doesn't know the height of
the man in pixels. You think you can do it? OK, open the
cameraman.tif image - the standard image that comes with MATLAB. Now,
tell me the height of the main in inches. See, you can't do it. OK,
now I'll even tell you that 150 pixels = 72 inches? STILL, you cannot
do it. ONLY when you know the height of the man in pixels (which Jo
does not - that's what she needs to measure) can you THEN convert the
pixels into a real world distance, not matter what software package
you're using.

Subject: how can we count the number of pixel in object

From: Ömer KAYA

Date: 2 Sep, 2010 14:40:24

Message: 22 of 25

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <3701ac4e-e92a-43c6-89af-0cc27c946126@l20g2000yqe.googlegroups.com>...
> Ömer KAYA:
> OK, fine. But the whole point is that she doesn't know the height of
> the man in pixels. You think you can do it? OK, open the
> cameraman.tif image - the standard image that comes with MATLAB. Now,
> tell me the height of the main in inches. See, you can't do it. OK,
> now I'll even tell you that 150 pixels = 72 inches? STILL, you cannot
> do it. ONLY when you know the height of the man in pixels (which Jo
> does not - that's what she needs to measure) can you THEN convert the
> pixels into a real world distance, not matter what software package
> you're using.

Ok, I see;

thanks for the heads up...

All have a nice evening...

Ömer KAYA
METU

Subject: how can we count the number of pixel in object

From: sidd rane

Date: 31 Oct, 2010 19:55:04

Message: 23 of 25

"Ömer KAYA" <e170531@metu.edu.tr> wrote in message <i5od0o$a2p$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <3701ac4e-e92a-43c6-89af-0cc27c946126@l20g2000yqe.googlegroups.com>...
> > Ömer KAYA:
> > OK, fine. But the whole point is that she doesn't know the height of
> > the man in pixels. You think you can do it? OK, open the
> > cameraman.tif image - the standard image that comes with MATLAB. Now,
> > tell me the height of the main in inches. See, you can't do it. OK,
> > now I'll even tell you that 150 pixels = 72 inches? STILL, you cannot
> > do it. ONLY when you know the height of the man in pixels (which Jo
> > does not - that's what she needs to measure) can you THEN convert the
> > pixels into a real world distance, not matter what software package
> > you're using.
>
> Ok, I see;
>
> thanks for the heads up...
>
> All have a nice evening...
>
> Ömer KAYA
> METU

Subject: how can we count the number of pixel in object

From: sidd rane

Date: 31 Oct, 2010 19:58:03

Message: 24 of 25

Hey can this be done by taking some reference point in the image like a scale in the picture can represent the inch or a feet distance .....

Can this be done ???

Subject: how can we count the number of pixel in object

From: ImageAnalyst

Date: 31 Oct, 2010 21:45:51

Message: 25 of 25

On Oct 31, 3:58 pm, "sidd rane" <sambo...@gmail.com> wrote:
> Hey can  this be done by taking some reference point in the image like a scale in the picture can represent the inch or a feet  distance .....
>
> Can this be done ???

-----------------------------------------
If you have a scale in your picture, then yes, you can spatially
calibrate.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us