itk image convert to vtkimagedata - vtk

I'm trying to read a DICOM image with ITK reader then convert it into vtkimagedata for rendering.
As I convert ITK image with "itk::ImageToVTKImageFilter" and render it in vtkrenderwindow, the origin of this volume is set at center of this volume. How can I do to set the coordinate of render window same to the DICOM image?
Here's my code:
vtkSmartPointer<vtkImageData> vtkImg = ITKconnectVTK(itkImg);
vtkSmartPointer<vtkImageData> ITKconnectVTK(ImageType::Pointer inputImg)
{
ConnectorType::Pointer connector = ConnectorType::New();
connector->SetInput(inputImg);
connector->Update();
return connector->GetOutput();
}

Here is an example which does just that:
https://itk.org/Wiki/VTK/ExamplesBoneYard/Cxx/VolumeRendering/itkVtkImageConvert
And another one which does not need an image:
https://itk.org/Wiki/ITK/Examples/WishList/IO/itkVtkImageConvertDICOM

You can read the direct dicom series in the VTK, and if you need some filter send the image to itk and then get it again.
reading with vtk:
https://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/ReadDICOM
convert from itk to vtk:
https://itk.org/Wiki/ITK/Examples/IO/ImageToVTKImageFilter
convert from vtk to itk
https://itk.org/Wiki/ITK/Examples/Broken/Images/VTKImageToImageFilter
you need to enable itkvtkglue in itk for this.

Related

Is there a way to ignore EXIF orientation data when loading an image with PIL?

I'm getting some unwanted rotation when loading images using PIL. I'm loading image samples and their binary mask, so this is causing issues. I'm attempting to convert the code to use openCV instead, but this is proving sticky. I haven't seen any arguments in the documentation under Image.load(), but I'm hoping there's a workaround I just haven't found...
There is, but I haven't written it all up. Basically, if you load an image with EXIF "Orientation" field set, you can get that parameter.
First, a quick test using this image from the PIL GitHub source Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg and run jhead on it you can see the EXIF orientation is 6:
jhead /Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg
File name : /Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg
File size : 4951 bytes
File date : 2020:04:24 14:00:09
Resolution : 128 x 128
Orientation : rotate 90 <--- see here
JPEG Quality : 75
Now do that in PIL:
from PIL import Image
# Load that image
im = Image.open('/Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg')
# Get all EXIF data
e = im.getexif()
# Specifically get orientation
e.get(0x0112)
# prints 6
Now click on the source and you can work out how your image has been rotated and undo it.
Or, you could be completely unprofessional ;-) and create a function called SneakilyRemoveOrientationWhileNooneIsLooking(filename) and shell out (subprocess) to exiftool and remove the orientation with:
exiftool -Orientation= image.jpg
Author's "much simpler solution" detailed in above comment is misleading so I just wanna clear that up.
Pillow does not automatically apply EXIF orientation transformation when reading an image. However, it has a method to do so: PIL.ImageOps.exif_transpose(image)
OpenCV automatically applies EXIF orientation when reading an image. You can disable this behavior by using the IMREAD_IGNORE_ORIENTATION flag.
I believe the author's true intention was to apply the EXIF orientation rather than ignore it, which is exactly what his solution accomplished.

Exchange data between VTK and ITK in Python

Sorry the naive question.
What is the way to exchange data between the VTK and ITK packages?
Example: Read a .mhd or .mha em VTK and using it in ITK registration.
Thanks,
Luis Gonçalves
Here's an example on how to convert a VTK image to an ITK image in python:
https://itk.org/ITKExamples/src/Bridge/VtkGlue/ConvertvtkImageDataToAnitkImage/Documentation.html
It uses ITK's itk.VTKImageToImageFilter. There is also a filter to go the other direction, ImageToVTKImageFilter.
Note that you can read .mha or .mhd file directly in ITK.

How to get bitmap of image from url

I want to load image from url and then convert it Bitmap.
objecturl.getString("imageurl");
and want to show it in imagview and then convert it into bitmap.
First step Sync gradle of Picasso to load image fro url.
implementation 'com.squareup.picasso:picasso:2.71828'
Second load image using picasso
String imgurl = objecturl.getString("imageurl");
Picasso.get().load(imgurl).into(imageView); //image will load successfully
Third use bitmap to convert image into bitmap
Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();

How to render / display multiframe dicom images in vtk?

I am using gdcm ImageReader to read multiframe dicom file. It reads multiframe correctly but I am unable to display the multiframe dicom file.
I am using vtkImageViewer to display single frame image,
vtkImageViewer viewer = new vtkImageViewer();
vtkDICOMImageReader reader = new vtkDICOMImageReader();
reader.SetInputfile(..\\inputFile);
viewer.SetInput(reader.GetOutput());
It displays single frame images correctly but does not display multiframe images.
Anybody knows how to display multiframe dicom files???
I would advise you to use vtkImageViewer2 instead of vtkImageViewer in this context. The former has a method, SetSlice, where, according to the documentation:
'Each call to SetSlice() changes the image data (slice) displayed AND changes the depth of the displayed slice in the 3D scene'
Example**:
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetSlice(5); //Specify the index/slice in image data
** Assumes you have set the input connection/data, example in c++ language.

how to correct the orientation of the image with ITK-VTK

I am a beginner in VTK ITK, I am trying to read a DICOM series with ITK and display with VTK but I had pictures upside down, I tried to read a single image (JPG) with ITK and visualuser with VTK it is the same problem, so I had the idea of ​​treating the image on photoshop ie I applied to the original image rotation (vertical symmetry of the work area) and I did the reading with ITK and display with VTK, the image is displayed in the correct orientation, infact ITK keeps the orientation of the image, but the problem is at VTK, it is which displays the image upside down, I searched all over the internet I have not found a solution or a method or not even an idea, I encountered the same problem in many forums but there is no response, I count on your help, I can not apply any image processing to find a solution to this problem.
Please Help! thank you in advance
Ideally you should re-orient your camera in VTK so that it is suited for medical image visualization. (The default camera in VTK uses the computer graphics conventions).
If you want a quick hack, you can copy-paste the following code in ITK:
FlipFilterType::Pointer flipperImage = FlipFilterType::New();
bool flipAxes[3] = { false, true, false };
flipperImage = FlipFilterType::New();
flipperImage->SetFlipAxes(flipAxes);
flipperImage->SetInput( image );
flipperImage->Update();
I use a rapid way to set the orientation:
imageActor->SetOrientation(180,0,0);
No need to add filter.
Here's an example of how I would do it. I'm not sure what classes you are using, so I cannot be specific.
vtkSmartPointer<vtkImageData> result = vtkSmartPointer<vtkIMageData>::New();
result->DeepCopy(YourImage); //DeepCopy your image to result
rImage->Update();
double val;
int i = 0;
for(vtkIdType f = result->GetNumberOfPoints()-1; f > -1; f--)
{
val = YourImage->GetPointData()->GetScalars()->GetTuple1(f);
result->GetPointData()->GetScalars->SetTuple1(i,val);
i++;
}
result->Update();
//Now Visualize your image

Resources