<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">the older versions of ITK-SNAP had index-based overlay, ignoring different spatial position which stem from different origin or direction vectors. I don't know whether the latest (3.6) breaks with that.</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">Slicer always uses spatial position and orientation, so for your experiments you should use Slicer to verify whether your code does what you want.</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">This difference in size setting should not matter, I think your calculation of the direction vectors is more likely cause of error. You could check that by setting different sizes in between the two extremes you trying right now. In case there is some bug in ITK (unlikely), you will flush it out with this. More likely this will make it more apparent to you what you are doing wrong.</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 Thu, May 11, 2017 at 12:00 PM, 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">Dear Dženan,<br>
<br>
<br>
Thank you for your swift reply.<br>
<br>
This is the entire function which I used:<br>
<br>
int ResampleImage(std::vector<<wbr>Vector3d> trajectory_points,<br>
std::vector<Vector3d> coordinate_system, InputImageType::Pointer image){<br>
<br>
        Vector3d traj_start, traj_end, third_point;<br>
        traj_start = <a href="http://trajectory_points.at" rel="noreferrer" target="_blank">trajectory_points.at</a>(0);<br>
        traj_end = trajectory_points.back();<br>
<br>
        third_point = traj_end + <a href="http://coordinate_system.at" rel="noreferrer" target="_blank">coordinate_system.at</a>(3) * 2 /<br>
image->GetSpacing()[0];<br>
<span class=""><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>
<br>
</span>        InputImageType::DirectionType imageDirection, trajectoryDirection;<br>
        imageDirection = image->GetDirection();<br>
        std::cout << "Image direction cosines : \n" << imageDirection << std::endl;<br>
<br>
        trajectoryDirection[0][0] = ST.normalized()[0];<br>
        trajectoryDirection[0][1] = ST.normalized()[1];<br>
        trajectoryDirection[0][2] = ST.normalized()[2];<br>
<span class=""><br>
        Vector3d second = normal_to_plane.cross(ST);<br>
        Vector3d normalized_second = second.normalized();<br>
</span>        trajectoryDirection[1][0] = normalized_second[0];<br>
        trajectoryDirection[1][1] = normalized_second[1];<br>
        trajectoryDirection[1][2] = normalized_second[2];<br>
<br>
        Vector3d normalized_normal = normal_to_plane.normalized();<br>
        trajectoryDirection[2][0] = normalized_normal[0];<br>
        trajectoryDirection[2][1] = normalized_normal[1];<br>
        trajectoryDirection[2][2] = normalized_normal[2];<br>
<br>
        std::cout << "Trajectory direction cosines : \n" << trajectoryDirection <<<br>
std::endl;<br>
<br>
        InputImageType::IndexType voxelIndex;<br>
        InputImageType::PointType point;<br>
<br>
        point[0] = traj_start[0], point[1] = traj_start[1], point[2] =<br>
traj_start[2];<br>
        image-><wbr>TransformPhysicalPointToIndex(<wbr>point, voxelIndex);<br>
        std::cout << "Index for point " << point << " is " << voxelIndex <<<br>
std::endl;<br>
<br>
        point[0] = traj_end[0], point[1] = traj_end[1], point[2] = traj_end[2];<br>
        image-><wbr>TransformPhysicalPointToIndex(<wbr>point, voxelIndex);<br>
        std::cout << "Index for point " << point << " is " << voxelIndex <<<br>
std::endl;<br>
<span class=""><br>
        double mpr_start[3] = { traj_start[0], traj_start[1], traj_start[2] };<br>
<br>
</span>        typedef itk::ResampleImageFilter<<wbr>InputImageType, InputImageType><br>
resampleFilterType;<br>
        resampleFilterType::Pointer resampleFilter = resampleFilterType::New();<br>
<br>
        typedef itk::<wbr>LinearInterpolateImageFunction<wbr><InputImageType, InputPixelType><br>
interpolatorType;<br>
        interpolatorType::Pointer linearInterpolator = interpolatorType::New();<br>
<br>
        resampleFilter-><wbr>SetInterpolator(<wbr>linearInterpolator);<br>
        resampleFilter-><wbr>SetDefaultPixelValue(-2000);<br>
        resampleFilter-><wbr>SetOutputSpacing(image-><wbr>GetSpacing());<br>
        resampleFilter-><wbr>SetOutputOrigin(mpr_start);<br>
        resampleFilter-><wbr>SetOutputDirection(<wbr>trajectoryDirection);<br>
        InputImageType::SizeType size;<br>
        size[0] = trajectory_points.size();<br>
        size[1] = 1.0 / image->GetSpacing()[1];<br>
        size[2] = 1.0 / image->GetSpacing()[2];<br>
        resampleFilter->SetSize(size); // This is for the trajectory, this<br>
corresponds to a size of [137, 8, 8] which is essentially the volume I want<br>
to extract.<br>
        //resampleFilter->SetSize(<wbr>image-><wbr>GetLargestPossibleRegion().<wbr>GetSize()); //<br>
This is for the entire resampled image<br>
        resampleFilter->SetInput(<wbr>image);<br>
        //resampleFilter->Update();<br>
<br>
        //InputImageType::Pointer resampled_image = InputImageType::New();<br>
        //resampled_image = resampleFilter->GetOutput();<br>
<br>
        FileWriter(resampleFilter-><wbr>GetOutput(),<br>
"C:/Users/api/Desktop/<wbr>resampled_volume_1.mhd");<br>
        return EXIT_SUCCESS;<br>
<br>
}<br>
<br>
I should also add that when I open the original image with the resampled<br>
image in ITK-SNAP (by adding another image), the overlay is exactly the<br>
same. Additionally, when I opened this in Slicer, only the top part of the<br>
volume seems to be rotated and the rest isn't. Kindly let me know if you<br>
need more information.<br>
I apologize for asking too many questions. We don't have an experienced ITK<br>
user in our lab, although vector understanding is sound :)<br>
<span class=""><br>
Thank you for your time.<br>
<br>
<br>
<br>
</span>--<br>
View this message in context: <a href="http://itk-users.7.n7.nabble.com/Extract-slice-from-ResampleFilter-tp38074p38230.html" rel="noreferrer" target="_blank">http://itk-users.7.n7.nabble.<wbr>com/Extract-slice-from-<wbr>ResampleFilter-tp38074p38230.<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>