<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Sidharta,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">you seem to have implemented what I suggested.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">"essentially copying the voxel values at the trajectory points and around it" can be achieved by using nearest neighbor interpolator instead of linear interpolator. But it looks like you are already using nearest neighbor, so you should try using linear interpolator, or even <a href="https://itk.org/Doxygen/html/classitk_1_1WindowedSincInterpolateImageFunction.html">windowed sinc</a> interpolator to get higher quality.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Regards,</div><div class="gmail_default"><font face="verdana, sans-serif">Dženan Zukić, PhD, Senior R&D Engineer, Kitware (Carrboro, N.C.)</font></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 19, 2017 at 9:40 AM, sidharta <span dir="ltr"><<a href="mailto:sidharta.gupta93@gmail.com" target="_blank">sidharta.gupta93@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Dženan,<br>
<br>
Thank you for your reply. I implemented this, and learned some cool stuff in<br>
3DSlicer (in order to compare the two images) but as you said, the size is<br>
difficult to compute. When I set the origin explicitly, to the start of the<br>
trajectory, the resampled image looks good in the direction I want it to be<br>
in, however, lot of information is lost. After putting my head into it for<br>
the past two weeks, I realized there are other ways to achieve I want this<br>
too. Does it make sense to you that I construct another 2D image (or 3D with<br>
thickness 1) by essentially copying the voxel values at the trajectory<br>
points and around it (probably the size equal to the dimensions of the<br>
original image in the x,y direction)? The aim ultimately is in fact to get<br>
one slice which best represents the HU values. I apologize for asking such<br>
silly questions.<br>
<br>
Just putting the code of what I did, let me know if it is in fact what you<br>
suggested me to do:<br>
<br>
Vector3d ST, SP, normal_to_plane;<br>
        ST = traj_end - traj_start;<br>
        SP = third_point - traj_start;<br>
        normal_to_plane = ST.cross(SP);<br>
        std::cout << "Vector ST : " << ST << " Vector SP : " << SP << " Direction<br>
of normal : " << normal_to_plane << std::endl;<br>
<br>
        InternalImageType::<wbr>DirectionType dir;<br>
        // vector from start to the end of the trajectory<br>
        Vector3d normalized_ST = ST.normalized();<br>
        dir[0][0] = normalized_ST[0];<br>
        dir[0][1] = normalized_ST[1];<br>
        dir[0][2] = normalized_ST[2];<br>
<br>
        Vector3d second = normal_to_plane.cross(ST);<br>
        Vector3d normalized_second = second.normalized();<br>
        dir[1][0] = normalized_second[0];<br>
        dir[1][1] = normalized_second[1];<br>
        dir[1][2] = normalized_second[2];<br>
<br>
        Vector3d normalized_normal = normal_to_plane.normalized();<br>
        dir[2][0] = normalized_normal[0];<br>
        dir[2][1] = normalized_normal[1];<br>
        dir[2][2] = normalized_normal[2];<br>
<br>
        // traj_start += normalized_second * 10;<br>
        double mpr_start[3] = { traj_start[0]  , traj_start[1] , traj_start[2]};<br>
<br>
        std::cout << "Previous image direction " << image->GetDirection() <<<br>
std::endl;<br>
        std::cout << "New Image Direction " << dir << std::endl;<br>
<br>
        getSliceMPR(image, mpr_start, dir);<br>
<br>
void getSliceMPR(InternalImageType:<wbr>:Pointer &image, double<br>
output_origin[Dimension], InternalImageType::<wbr>DirectionType dir)<br>
{<br>
<br>
        // Instantiate Resample Filter here<br>
<span class="">        ResampleFilterType::Pointer filter = ResampleFilterType::New();<br>
</span>        // Instantiate Transform for resampling<br>
        // Changing the Output direction instead of setting the transform<br>
        // filter->SetTransform(<wbr>transform);<br>
<span class=""><br>
        typedef itk::<wbr>NearestNeighborInterpolateImag<wbr>eFunction<<br>
                InternalImageType, double> InterpolatorType;<br>
<br>
</span>        // Instantiate the interpolator<br>
<span class="">        InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>
        filter->SetInterpolator(<wbr>interpolator);<br>
<br>
</span>        // Set pixels of the output image that end up being mapped outside the<br>
extent of the input image to -1500<br>
        filter->SetDefaultPixelValue(-<wbr>1500);<br>
<br>
        // Sampling grid of the output space - pixel spacing in mm<br>
        // Hard coded here<br>
        filter->SetOutputSpacing(<wbr>image->GetSpacing());<br>
<br>
<br>
    // filter->SetOutputOrigin(image-<wbr>>GetOrigin());<br>
<br>
        filter->SetOutputOrigin(<wbr>output_origin);<br>
        filter->SetOutputDirection(<wbr>dir);<br>
        InternalImageType::SizeType size;<br>
        filter->SetSize(image-><wbr>GetLargestPossibleRegion().<wbr>GetSize());<br>
<br>
        filter->SetInput(image);<br>
<br>
        typedef itk::ImageFileWriter<<wbr>InternalImageType> WriterType;<br>
<br>
        WriterType::Pointer writer = WriterType::New();<br>
        writer->SetFileName("C:/Users/<wbr>api/Desktop/Resampled/<wbr>resampled_2.mhd");<br>
        writer->SetUseCompression(<wbr>true);<br>
        writer->SetInput(filter-><wbr>GetOutput());<br>
        try{<br>
                writer->Update();<br>
<br>
        }<br>
        catch (itk::ExceptionObject & excep){<br>
<br>
                std::cerr << "Exception catched!.." << std::endl;<br>
                std::cerr << excep << std::endl;<br>
        }<br>
<br>
}<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://itk-users.7.n7.nabble.com/Extract-slice-from-ResampleFilter-tp38074p38129.html" rel="noreferrer" target="_blank">http://itk-users.7.n7.nabble.<wbr>com/Extract-slice-from-<wbr>ResampleFilter-tp38074p38129.<wbr>html</a><br>
<div class="HOEnZb"><div class="h5">Sent from the ITK - Users mailing list archive at Nabble.com.<br>
______________________________<wbr>_______<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br></div>