I want to calculate the white area of contour

"How can I calculate the white area of this contour?"
In my opinion, the number of white pixels corresponds to the white area I think.
If it is right, could you explain that how to count the number of white pixels.
Or do you have any other idea to calculate the area, please let me know.
thank you.
Here is m-file that creates contour.
clear;
clf;
clc;
filename = 'project.txt';
datatable = load(filename);
data = datatable(2:end,2:end);
length = datatable(1,2:end);
time = datatable(2:end,1).';
datasize=size(data);
row=datasize(1,1);
column=datasize(1,2);
row=1:row;
[c,h]=contourf(length,row',data,[20 2 30]);
colormap gray
grid on
hold on

Answers (1)

I don't have your data file so I can't run your code. But it looks like a gray image with the white being 255 so the usual code for that is
whitePixels = grayImage == 255; % A logical (binary) image
numberOfWhitePixels = sum(whitePixels(:));

5 Comments

Jeong
Jeong on 23 Jul 2012
Edited: Jeong on 23 Jul 2012
thank you very munch.
And I have one more question.
In this case, should I make a JPEG file from the contour to run your code?
or is it possible calulate the number of white pixels from contour directly?
In this adress, there is 'project.txt'file that you can run.
My code just operates off the image, like the one you are showing. I don't care what format the image was stored it. It might have been JPG, PNG, BMP, TIFF, or whatever. That doesn't matter. All that matters is the image after you've read it in from disk. If you have the x,y coordinates of some contour line(s) then of course you can get the value of the image at those locations.
Jeong
Jeong on 24 Jul 2012
Edited: Jeong on 24 Jul 2012
So once I have to save contour image as JPG,PNG,BMP,TIFF before running your code by using a mouse since I'm a beginner.
If you know a code that can save contour image directly, please let me know.
Thanks for your kind reply.
You can try export_fig - see the first page of the File Exchange. It's always the top download.
Thanks a lot!

Sign in to comment.

Categories

Asked:

on 23 Jul 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!