how to calculate irregular shape area



  • 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:

    So, first of all, you have to understand what kind of method you have to use to "select" your object.
  • i already got to select the object.object already selected.i do not understand about your coding.can you give detail to me?
  • Ok, you have an image with a white object and black background.
    So, count the white pixels:
    Now convert into centemeters:

  • i must declare reference object length in centemeters and reference object length in pixel right?
  • 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).
  • 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.
    [code]Image=zeros(30); Image(4:6,4:6)=1;
    disp(['the area is:' num2str(white_pixel_count) 'cm2']);[/code]
  • opss..i forgot to put another now its already can read the value of pixel..=)
  • Well done!
  • not done..i'm now try to get the value of area in cm2.i have error of that coding..
  • 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.

    can u help me for that coding. i am using this as reference value.
  • 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[italic] message = sprintf('Number of pixels = %d', ...
    [/italic]this coding but its not can i display that value when its already count?
  • I was wrong, de disp in the previous post had to be in this way:
    [code]disp(['the area is:' num2str(white_pixel_count) 'pixels']);[/code]
    Then, you have to add the code for the conversion, combining the two codes I gave you:

    Image=zeros(30); Image(4:6,4:6)=1;
    disp(['the area is:' num2str(objectAreaInCentemeters) 'cm2']);[/code]

    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.
  • centemetersInOnePixelSquare=centemetersInOnePixel^2;

    when this coding functioning?

  • centemetersInOnePixelSquare=centemetersInOnePixel^2;

    when this coding functioning?

  • ok..i got it..i'm already understand that coding..thank 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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!