[Insight-users] How to calculate distance between 2 points in millimeter

Cary lorey developement.unity at gmail.com
Wed Jun 5 20:51:59 EDT 2013


I am trying to read a DICOM image with itk and visualize it with vtk and
see, I tried to get the resolution with itk but there is no method that
allows, I recovers just the length and width of the image in pixels.
 if you have an idea how to get the resolution of an image  can you  help
me with please

 thank you Nuwan Jayala for the answer but I did not find the
method  getspacing in itk.

 I tried another example of vtkDistanceWidget class, I tried to read a jpg
image and I get the measurement between two points  millimeter and it works
well. but when I changed the type of  image on DICOM , the value of the
measurement is not correct, I did not understand where the problem is!!!!!

Please can you help me please .here is my code with vtkDistanceWidget (the
version that works with jpg is commented):

int main(int, char *[])
{
/*std::string inputFilename = "C:/nature.jpg";

  //Read the image
  vtkSmartPointer<vtkJPEGReader> jpegReader =
    vtkSmartPointer<vtkJPEGReader>::New();
   jpegReader->SetFileName ( inputFilename.c_str() );*/

std::string inputFilename = "C:/dicom decompress/dicom
decompress/GM_23/2801/0/000121988";

LectureFileDicom(inputFilename);

typedef itk::FlipImageFilter< ImageType >   FlipImageFilterType;

FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New ();
  flipFilter->SetInput( reader->GetOutput() );
  bool flipAxes[3] = { false, true, false };
flipFilter->SetFlipAxes(flipAxes);
flipFilter->Update();

Connector->SetInput( flipFilter->GetOutput() );
Connector->Update();


vtkSmartPointer<vtkImageViewer2> imageViewer =
    vtkSmartPointer<vtkImageViewer2>::New();
 // imageViewer->SetInputConnection( jpegReader->GetOutputPort() );
imageViewer->SetInput(Connector->GetOutput());


  // An interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
   imageViewer->SetupInteractor(renderWindowInteractor);
 imageViewer->Render();

  vtkSmartPointer<vtkDistanceWidget> distanceWidget =
    vtkSmartPointer<vtkDistanceWidget>::New();
  distanceWidget->SetInteractor(renderWindowInteractor);
 // distanceWidget->CreateDefaultRepresentation();
  static_cast<vtkDistanceRepresentation
*>(distanceWidget->GetRepresentation())
    ->SetLabelFormat("%-#6.3g mm");

  // Render an image (lights and cameras are created automatically)


  renderWindowInteractor->Initialize();

  distanceWidget->On();

  // Begin mouse interaction
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}


2013/6/5 Jon Haitz Legarreta <jhlegarreta at vicomtech.org>

> Dear Cary,
> ITK will give you the distance in image units, i.e. pixel/voxels. You
> should ask your image object about its resolution (how many physical
> distance units each pixel accounts for) and then do the conversion.
>
> HTH,
> JON HAITZ
>
>
> On 4 June 2013 01:35, Cary lorey <developement.unity at gmail.com> wrote:
>
>> Hello,
>>
>> I am trying to calculate the distance between 2 points on an image, I
>> modified the code TestDistanceWidget according to my needs, but the problem
>> when I measure the distance between the 2 points, the value is high, then I
>> want a millimeter distance.
>>
>> Please please can you help me?
>>
>> thank you in advance.
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.php
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130606/d01db6ff/attachment.htm>


More information about the Insight-users mailing list