[Rtk-users] DRR image generation from 3D CT
Isuru Suranga Wijesinghe
isurusuranga.wijesinghe at gmail.com
Wed Apr 22 10:09:53 EDT 2020
Hi,
I have tried to save the out image as .png and it gave an error as below.
itk::ImageFileWriterException (0000003E08EFFCC0) Location: "unknown"
File: D:\ITK\Source\Modules\IO\ImageBase\include\itkImageFileWriter.hxx
Line: 128 Description: Could not create IO object for writing file
E:/DRRGeneratedDataset/one_CT/DRR_RTK/first.png
Tried to create one of the following:
GDCMImageIO
MetaImageIO
TIFFImageIO
You probably failed to set a file suffix, or set the suffix to an
unsupported type.
And when changing the output extension to .mha it gives below error.
'FirstReconstruction.exe' (Win32): Loaded
'C:\Windows\System32\kernel.appcore.dll'.
Exception thrown at 0x00007FF68D387919 in FirstReconstruction.exe:
0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
I have attached the source code (.cpp) file for your further reference.
Please let me know if I have done any mistake.
On Tue, Apr 21, 2020 at 4:43 PM Simon Rit <simon.rit at creatis.insa-lyon.fr>
wrote:
> Projection is centered on point (0,0,0) mm in your input
> (PhaseImage_01.mha) (as described in the doc). Check where this point is in
> your input. If it's outside, then you need to modify its origin (in the ITK
> sense, check ITK doc).
>
> On Tue, Apr 21, 2020 at 5:36 PM Isuru Suranga Wijesinghe <
> isurusuranga.wijesinghe at gmail.com> wrote:
>
>> Hi,
>>
>> I have built rtkforwardprojections code. And pass the appropriate
>> parameters to the generated exe from the command line as below.
>> But there is nothing in the output location. I have attached herewith my
>> geomtry.xml as well.
>>
>> D:/RTK/Build/bin/Release>rtkforwardprojections -g D:/geomtry.xml -i
>> D:\\Subject_01\\CT\\PhaseImage_01.mha -o D:/_rtk_output.png
>>
>> On Mon, Apr 20, 2020 at 8:45 PM Simon Rit <simon.rit at creatis.insa-lyon.fr>
>> wrote:
>>
>>> Hi,
>>> Look at the doc on the geometry file
>>> <http://www.openrtk.org/Doxygen/DocGeo3D.html> and rtksimulatedgeometry
>>> <https://github.com/SimonRit/RTK/tree/master/applications/rtksimulatedgeometry>
>>> for creating one file. AddProjection
>>> <http://www.openrtk.org/Doxygen/classrtk_1_1ThreeDCircularProjectionGeometry.html#a39d6a67147cac1f2b5d75f5958a48f9a>
>>> takes several parameters. Given your scheme, it should look like
>>> AddProjection(1000, 1536, angle, +/-190 etc)
>>> It looks like an Elekta geometry given the distances, check the example
>>> here
>>> <http://wiki.openrtk.org/index.php/RTK/Examples/ElektaReconstruction>
>>> if you can get access to the database.
>>> Simon
>>>
>>> On Mon, Apr 20, 2020 at 9:31 PM Isuru Suranga Wijesinghe <
>>> isurusuranga.wijesinghe at gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm currently looking rtkforwardprojections example [1] to generate DRR
>>>> images from 3D-CT volumes. My question is how can I set custom geometric
>>>> configurations as in the sample attached image ?
>>>>
>>>> Can you please help with a relevant example of this. ?
>>>>
>>>> [1]
>>>> https://github.com/SimonRit/RTK/blob/b32cffdc6f9d7a432c50023c370ed996a7985b69/applications/rtkforwardprojections/rtkforwardprojections.cxx
>>>>
>>>> Thanks and Best Regards,
>>>> Isuru
>>>> _______________________________________________
>>>> Rtk-users mailing list
>>>> Rtk-users at public.kitware.com
>>>> https://public.kitware.com/mailman/listinfo/rtk-users
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/rtk-users/attachments/20200422/070ba182/attachment-0001.html>
-------------- next part --------------
// RTK includes
#include <rtkConstantImageSource.h>
#include <rtkThreeDCircularProjectionGeometryXMLFileWriter.h>
#include <rtkRayEllipsoidIntersectionImageFilter.h>
#include <rtkFDKConeBeamReconstructionFilter.h>
#include <rtkFieldOfViewImageFilter.h>
#include "rtkJosephForwardProjectionImageFilter.h"
#include "rtkJosephForwardAttenuatedProjectionImageFilter.h"
// ITK includes
#include <itkImageFileWriter.h>
int main(int argc, char **argv)
{
using OutputPixelType = float;
constexpr unsigned int Dimension = 3;
// Defines the image type
using ImageType = itk::Image< float, Dimension >;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;
bool attenuationmap_given = false;
// Defines the RTK geometry object
using GeometryType = rtk::ThreeDCircularProjectionGeometry;
GeometryType::Pointer geometry = GeometryType::New();
unsigned int numberOfProjections = 1;
double firstAngle = 0;
double angularArc = 360;
unsigned int sid = 1000; // source to isocenter distance
unsigned int sdd = 1560; // source to detector distance
//double projectionOffset = 190;
for(unsigned int noProj=0; noProj<numberOfProjections; noProj++)
{
double angle = firstAngle + noProj * angularArc / numberOfProjections;
geometry->AddProjection(sid, sdd, angle);
}
// Write the geometry to disk
rtk::ThreeDCircularProjectionGeometryXMLFileWriter::Pointer xmlWriter;
xmlWriter = rtk::ThreeDCircularProjectionGeometryXMLFileWriter::New();
xmlWriter->SetFilename("E:/DRRGeneratedDataset/one_CT/geometry/geometry.xml");
//xmlWriter->SetObject(geometry);
xmlWriter->SetObject(&(*geometry));
try
{
std::cout << "XML writer image" << std::endl;
xmlWriter->WriteFile();
}
catch (itk::ExceptionObject& err)
{
std::cerr << "ERROR: ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
}
// Create a stack of empty projection images
using ConstantImageSourceType = rtk::ConstantImageSource< ImageType >;
ConstantImageSourceType::Pointer constantImageSource = ConstantImageSourceType::New();
ConstantImageSourceType::PointType origin;
ConstantImageSourceType::SpacingType spacing;
ConstantImageSourceType::SizeType sizeOutput;
origin[0] = -127;
origin[1] = -127;
origin[2] = 0.;
sizeOutput[0] = 128;
sizeOutput[1] = 128;
//numberOfProjections = gantryangles
sizeOutput[2] = numberOfProjections;
spacing.Fill(2.);
constantImageSource->SetOrigin(origin);
constantImageSource->SetSpacing(spacing);
constantImageSource->SetSize(sizeOutput);
constantImageSource->SetConstant(0.);
using ReaderType = itk::ImageFileReader<OutputImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("E:/DRRGeneratedDataset/one_CT/PhaseImage_01.mha");
//TRY_AND_EXIT_ON_ITK_EXCEPTION(reader->Update())
try
{
std::cout << "reading image" << std::endl;
reader->Update();
}
catch (itk::ExceptionObject& err)
{
std::cerr << "ERROR: ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
}
itk::ImageSource<OutputImageType>::Pointer attenuationFilter;
if (attenuationmap_given)
{
// Read an existing image to initialize the attenuation map
using AttenuationReaderType = itk::ImageFileReader<OutputImageType>;
AttenuationReaderType::Pointer attenuationReader = AttenuationReaderType::New();
attenuationReader->SetFileName("");
attenuationFilter = attenuationReader;
}
rtk::ForwardProjectionImageFilter<OutputImageType, OutputImageType>::Pointer forwardProjection;
forwardProjection = rtk::JosephForwardProjectionImageFilter<OutputImageType, OutputImageType>::New();
forwardProjection->SetInput(constantImageSource->GetOutput());
forwardProjection->SetInput(1, reader->GetOutput());
if (attenuationmap_given)
{
forwardProjection->SetInput(2, attenuationFilter->GetOutput());
}
forwardProjection->SetGeometry(geometry);
// Write
using WriterType = itk::ImageFileWriter<OutputImageType>;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("E:/DRRGeneratedDataset/one_CT/DRR_RTK/first.png");
writer->SetInput(forwardProjection->GetOutput());
//TRY_AND_EXIT_ON_ITK_EXCEPTION(writer->Update())
try
{
std::cout << "Writing image " << std::endl;
writer->Update();
}
catch (itk::ExceptionObject& err)
{
std::cerr << "ERROR: ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
}
return EXIT_SUCCESS;
}
More information about the Rtk-users
mailing list