ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Circle area and perimeter calculations
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yeohray2

Malaysia
106 Posts

Posted - Feb 21 2022 :  02:48:35  Show Profile  Reply
Hi, I needed to create a circular region of interest. To do that, I let the user create a ellipse-type shape layer using mlCreateShapeLayers, then convert that shape to a polyline. That all works fine.

However, when I calculate the area and length using the polyline layers' CalculateArea and CalculateLength methods respectively, the values differ compared to using the 'normal' circle formulas i.e. pi * (r squared) and 2 * pi * r.

Is it because the polyline circle is made up of many small shapes, hence the different values for area and length?

Thanks in advance.

Regards
Ray Mond

xequte

38608 Posts

Posted - Feb 22 2022 :  20:46:50  Show Profile  Reply
Hi Ray

For elliptical and rectangular measurement you are better to use a TIETextLayer with a visible BorderShape.

Compare the following:

  // THREE WAYS TO CALCULATE PERIMETER AND AREA OF AN ELLIPSE

  // 1. Shape Layer
  ImageEnView1.LayersAdd( iesEllipse, 10, 10, 400, 250 );
  ImageEnView1.CurrentLayer.RulerUnits := ieuPixels;
  memo1.Lines.Add( 'Shape Perim : ' + FloatToStr( ImageEnView1.CurrentLayer.RulerValue( ierLength )));
  memo1.Lines.Add( 'Shape Area  : ' + FloatToStr( ImageEnView1.CurrentLayer.RulerValue( ierArea )));

  // 2. Text Layer
  ImageEnView1.LayersAdd( ielkText, 10, 410, 400, 250 );
  ImageEnView1.CurrentLayer.FillColor := clRed;
  ImageEnView1.CurrentLayer.RulerUnits := ieuPixels;
  ImageEnView1.CurrentLayer.RulerMode := iermLabel;
  TIETextLayer( ImageEnView1.CurrentLayer ).BorderShape := iesEllipse;
  memo1.Lines.Add( 'Text Perim  : ' + FloatToStr( ImageEnView1.CurrentLayer.RulerValue( ierLength )));
  memo1.Lines.Add( 'Text Area   : ' + FloatToStr( ImageEnView1.CurrentLayer.RulerValue( ierArea )));

  // 3. Polyline Layer (less accurate)
  ImageEnView1.LayersAdd( iesEllipse, 10, 810, 400, 250 );
  TIEShapeLayer( ImageEnView1.CurrentLayer ).ConvertToPolylineLayer();
  IEGlobalSettings().LayerCurveQuality := 36; // Less points to reduce complexity
  memo1.Lines.Add( 'Poly Perim   : ' + FloatToStr( TIEPolylineLayer( ImageEnView1.CurrentLayer ).CalculateLength( ieuPixels  )));
  memo1.Lines.Add( 'Poly Area    : ' + FloatToStr( TIEPolylineLayer( ImageEnView1.CurrentLayer ).CalculateArea( ieuPixels  )));

  ImageEnView1.Update;

  { Returns:
  Shape Perim : 1047.851
  Shape Area  : 78539.816
  Text Perim  : 1047.851
  Text Area   : 78539.816
  Poly Perim  : 1028.604
  Poly Area   : 77512.826
  }


Please see: https://www.imageen.com/help/TIELayer.RulerValue.html
But note that documentation is outdated as now all layer types support ierArea and ierLength.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

yeohray2

Malaysia
106 Posts

Posted - Feb 23 2022 :  10:52:20  Show Profile  Reply
Hi, thanks for the suggestion to use text layers. However, I need to also calculate values for the area in the shape. These are DICOM images, and I'm using the IEIsPointInPoly function to calculate the mean and standard deviation for the HU values for the area within the shape.

Ray
Go to Top of Page

xequte

38608 Posts

Posted - Feb 23 2022 :  15:01:54  Show Profile  Reply
Hi Ray

So it is not always elliptical?

If it is, you can use IEPointInEllipse()

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

yeohray2

Malaysia
106 Posts

Posted - Feb 23 2022 :  20:44:55  Show Profile  Reply
Hi Nigel,

Thanks, I wasn't aware of that function, will take a look at it.

Ray
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: