Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1467
Number of posts: 2144

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to calculate irregular shape area Posted by ayuni on 30 Dec 2011 at 11:55 PM
hi,
i have the project that needs to me to develop the source code for calculate irregular shape area for cataracts in the iris of eye.i have the problem to do this solution.so,can anyone help me to make the solution.My project is for detect and extract the irregular shape and must calculate the area of irregular shape(region of interest).
Report
Re: how to calculate irregular shape area Posted by giug on 4 Jan 2012 at 2:54 AM
You can make a blak&white image, with a white region of interest and a black background, and then simply count the white pixel. The methods to be used to obtain the b&w image depends on the image characteristics.
Report
Re: how to calculate irregular shape area Posted by ayuni on 15 Jan 2012 at 12:20 PM
what do you mean with characteristic of image?what's example methods that you can give?how to calculate in pixel and do you know how to calculate in cm per square.
Report
Re: how to calculate irregular shape area Posted by giug on 16 Jan 2012 at 3:45 PM
Sorry, I hadn't read this post.
I try to explain.
If you have an image with a dark backgroud, and the object is ligther than the background you can use a pixel based segmentation: all the pixels that have their value smaller than a threshold become black, the pixels that have a value higher than the threshold become white. In this way in the b&w image, you have your object in white and the background in black. See the im2bw function in the matlab help for more references.
If the object in your image has visible edges, probably it is better to use an edge based segmentation. You filter the image with a "high pass" filter that enphatise the edges of your image giving a b&w image with the edges in white and the background in black (see the edge function in the matlab help). Then, you fill the edges (imfill function).

So, it depends on your image...
Report
Re: how to calculate irregular shape area Posted by giug on 4 Jan 2012 at 2:56 AM
You can make a blak&white image, with a white region of interest and a black background, and then simply count the white pixels. The methods to be used to obtain the b&w image depends on the image characteristics.
Report
Re: how to calculate irregular shape area Posted by ark5230 on 15 Jan 2012 at 8:40 AM
But how to count pixels ??
Report
Re: how to calculate irregular shape area Posted by ark5230 on 15 Jan 2012 at 8:48 AM
But how to count pixels ??
Report
Re: how to calculate irregular shape area Posted by giug on 16 Jan 2012 at 2:50 AM
If you have to count white pixels and your image is a double image (use im2double if it is not), the white pixelòs are represented by 1 (black is 0) you can count in this way:
white_pixel_count=length(find(YOUR_IMAGE==1));
this is one way.
Report
Re: how to calculate irregular shape area Posted by ayuni on 16 Jan 2012 at 7:03 AM
do you know how to count in cm per square for the area?
Report
Re: how to calculate irregular shape area Posted by giug on 16 Jan 2012 at 3:33 PM
You need to know the resolution of the image.
i.e. how many pixels in one cm, or how many dpi.
Then, you have only to multiply for the number of white pixels and you have the area in cm.
Report
Re: how to calculate irregular shape area Posted by ayuni on 25 Jan 2012 at 8:33 PM
i know about the value of dpi..so, how can i calculate the area?but i don't know the value of pixel in one cm..
Report
Re: how to calculate irregular shape area Posted by ayuni on 25 Jan 2012 at 8:54 PM
i have 96dpi horizontal resolution and 96dpi vertical resolution.so,how can i calculate the area?if i have 1540pixel,it's not logic to multiple that value.
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 1:22 AM
The problem is: how do you "create" the image? With a camera? or it was a film and you use a scanner to digitize it?
Is the area of the object refferred to a real object so that you have to know the actual size of the real object?

Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 1:40 AM
oh..i don't know the real size of object because i just take a picture from google image.so,i have big problem.i need to get the real image.my image refer to cataract image.
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 1:56 AM
Ok, if you have a google image, probably you have no information about the camera. Imagine that the size of the object represented in a photograph depends also on the zoom used to take the photo and on the distance of the camera from the object.
So, I think that you need some reference in the image, like "this object is n cm wide, so n cm corresponds to m pixels, and so the area is...".

Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 2:07 AM
so,in programming how can i calculate the area for that image?let say i just do like your statement.how the code should i do?
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 2:59 AM
Ok, you have to calculate the area in pixel using a technique explained in my post on 16Jan, obtaining a black and white image (object in white (1) and background in black(0)) then counting the number of white pixels.
Then you make the proportion with the reference object:
ref_px:ref_cm=obj_px:obj_cm

So, first of all, you have to understand what kind of method you have to use to "select" your object.
Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 5:08 AM
i already got to select the object.object already selected.i do not understand about your coding.can you give detail to me?
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 5:41 AM
Ok, you have an image with a white object and black background.
So, count the white pixels:
objectAreaInPixels=length(find(Image==1));

Now convert into centemeters:
centemetersInOnePixel=referenceObjectLengthInCentemeters/referenceObjectLengthInPixels;
centemetersInOnePixelSquare=centemetersInOnePixel^2;
objectAreaInCentemeters=objectAreaInPixels*centemetersInOnePixel;



Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 5:54 AM
i must declare reference object length in centemeters and reference object length in pixel right?
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 5:57 AM
Yes, you need to have these information.
To measure the number of pixels of the reference object in your image you can use the imdistline matlab function (you draw a line on the image and matlab returns the length of the line in pixels).
Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 3:04 PM
white_pixel_count=length(find(Image==1));

Image is in binary image?i try to display the length that already count by that coding by using message = sprintf('Number of pixels = %d', ...
white_pixel_count);
this coding but its not functioning.how can i display that value when its already count?
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 7:43 AM
As I wrote in the previous posts, the image with the object has to be a black and white image. It means that is a matrix with only zeros (black) and ones (white).
Where do you want to display the message?
You can display it in the command window using the disp funcion.
Let's try this simple code and check what I mean.
Image=zeros(30); Image(4:6,4:6)=1;
figure();imshow(Image);
white_pixel_count=length(find(Image==1));
disp(['the area is:' num2str(white_pixel_count) 'cm2']);

Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 7:44 AM
opss..i forgot to put another coding..so now its already can read the value of pixel..=)
Report
Re: how to calculate irregular shape area Posted by giug on 26 Jan 2012 at 7:52 AM
Well done!
Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 8:11 AM
not done..i'm now try to get the value of area in cm2.i have error of that coding..
Report
Re: how to calculate irregular shape area Posted by ayuni on 26 Jan 2012 at 8:32 AM
that coding for area in cm2 is not function.when using that coding,it give it the output value with the output for pixel area.this coding not function well.
objectAreaInCentemeters=objectAreaInPixels*centemetersInOnePixel;

can u help me for that coding. i am using this as reference value.
referenceObjectLengthInCentemeters=100;
referenceObjectLengthInPixels=1000;
Report
Re: how to calculate irregular shape area Posted by giug on 27 Jan 2012 at 1:05 AM
I was wrong, de disp in the previous post had to be in this way:
disp(['the area is:' num2str(white_pixel_count) 'pixels']);

Then, you have to add the code for the conversion, combining the two codes I gave you:

referenceObjectLengthInCentemeters=100;
referenceObjectLengthInPixels=1000;
Image=zeros(30); Image(4:6,4:6)=1;
figure();imshow(Image);
objectAreaInPixels=length(find(Image==1));
centemetersInOnePixel=referenceObjectLengthInCentemeters/referenceObjectLengthInPixels;
centemetersInOnePixelSquare=centemetersInOnePixel^2;
objectAreaInCentemeters=objectAreaInPixels*centemetersInOnePixel;
disp(['the area is:' num2str(objectAreaInCentemeters) 'cm2']);


Let's try this code with the phantom image so that you can check the steps of the code by hand, and understand what you are doing.
Report
Re: how to calculate irregular shape area Posted by ayuni on 27 Jan 2012 at 7:12 PM
centemetersInOnePixelSquare=centemetersInOnePixel^2;

when this coding functioning?


Report
Re: how to calculate irregular shape area Posted by ayuni on 27 Jan 2012 at 7:14 PM
centemetersInOnePixelSquare=centemetersInOnePixel^2;

when this coding functioning?


Report
Re: how to calculate irregular shape area Posted by ayuni on 27 Jan 2012 at 7:42 PM
ok..i got it..i'm already understand that coding..thank you..my problem now to get the value of "referenceObjectLengthInPixels"..i'm try to find it by using your suggestion by using "imdistline"...but do you have any idea if i can gel the reference object lenght in pixel automatically without using "imdistline"...because i want to get it automatically without using manual style.
Report
Re: how to calculate irregular shape area Posted by ayuni on 27 Jan 2012 at 7:57 PM
i am using "Black_pixel_count=length(find(Image==0))" this coding to find the "reference Object Length In Pixels"..the full coding i am using "reference Object Length In Pixels = Black_pixel_count=length(find(Image==0)) + white_pixel_count=length(find(Image==0))". it is possible i am using this coding?
Report
Re: how to calculate irregular shape area Posted by giug on 30 Jan 2012 at 12:47 AM
I can't understand your last post.
The number of black pixel in a black and white image is the number of pixels of the image minus the number of white pixels.
I can't understand why you want to count the number of black pixels.
Report
Re: how to calculate irregular shape area Posted by giug on 30 Jan 2012 at 12:41 AM
You have to segment the reference object such as the object you want to calculate the area, with one of the techniques cited above (as usual, it depends on the characteristics of the reference object).
Then, you obtain a black and white image with only the reference object (reference object in white, other pixels in black) and mesure the length of the object (not the number of white pixels, that is the area of the object).
Report
Re: how to calculate irregular shape area Posted by ayuni on 30 Jan 2012 at 8:25 PM
i do like that to get the total of the pixel in that image for the reference value as the "reference Object Length In Pixels" because i don't know how to get it other than using your example code "imdistline".
Report
Re: how to calculate irregular shape area Posted by giug on 31 Jan 2012 at 12:26 AM
The length of the image is the number of rows:
size(image,1)

The height of the image is the number of cols:
size(image,2)

The area in pixels is length*height (because it is a rectangle).
Report
Re: how to calculate irregular shape area Posted by ayuni on 31 Jan 2012 at 6:13 PM
can you give your email?then i will sent to you exactly what i really mean about my project.i do not understand about the previous coding. size(image,1) and size(image,2)

Report
Re: how to calculate irregular shape area Posted by giug on 1 Feb 2012 at 12:57 AM
Send me a private message on this forum.
Report
Re: how to calculate irregular shape area Posted by ayuni on 1 Feb 2012 at 6:03 PM
how can i go to private message?
Report
Re: how to calculate irregular shape area Posted by ayuni on 1 Feb 2012 at 7:47 PM
how can i using imdistline coding?
Report
Re: how to calculate irregular shape area Posted by ayuni on 1 Feb 2012 at 7:59 PM
can u send to private message to me first?i cannot send it to you.
Report
Re: how to calculate irregular shape area Posted by giug on 2 Feb 2012 at 1:26 AM
Ok, check your programmersheaven mailbox. On the top right of the programmersheaven page, on "my mailbox".



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.