Re: [ITK-users] [ITK] Image conversion from 3D volume to 2D slices
Dženan Zukić <[email protected]> Wed, 8 May 2019 14:17:20 -0400
| Newsgroups | gmane.comp.lib.itk.user |
|---|---|
| Message-ID | <CAPf2UMThLrzFJ1JQJMqgBa1Ks2P1+jkG5K=kBhfduJoVsv46cA@mail.gmail.com> |
--===============1942928187== Content-Type: multipart/alternative; boundary="000000000000da2a50058864589b" --000000000000da2a50058864589b Content-Type: text/plain; charset="UTF-8" Definitions of RescaleFilterType and FilterType should be like this: typedef itk::RescaleIntensityImageFilter< InputImageType, OutputImageType > RescaleFilterType; typedef itk::ExtractImageFilter< OutputImageType, OutputImageType > FilterType; On Wed, May 8, 2019 at 1:54 PM Shrabani Ghosh <[email protected]> wrote: > I did it like this and I am getting images like this now. > <http://itk-insight-users.2283740.n2.nabble.com/file/t396636/slice1.png> > > > > int main( int argc, char ** argv ) > { > > //typedef signed short InputPixelType; > /*typedef unsigned char InputPixelType; > typedef unsigned char OutputPixelType;*/ > typedef signed short InputPixelType; > typedef unsigned char OutputPixelType; > typedef itk::Image< InputPixelType, 3 > InputImageType; > typedef itk::Image< OutputPixelType, 2 > OutputImageType; > typedef itk::ImageFileReader< InputImageType > ReaderType; > typedef itk::ImageFileWriter< OutputImageType > WriterType; > const char * inputFilename = "G:/My Drive/BMES2019/New > folder/subject1.nii"; > > { > int i = 1; > > std::string str="input//"; > std::string s1="slice"; > std::string s2 = std::to_string(i); > std::string s3=".png"; > std::string s4=str+s1+s2+s3; > const char *mycharp = s4.c_str(); > > const char * outputFilename = mycharp; > > ReaderType::Pointer reader = ReaderType::New(); > WriterType::Pointer writer = WriterType::New(); > > reader->SetFileName( inputFilename ); > writer->SetFileName( outputFilename ); > > typedef itk::RescaleIntensityImageFilter< InputImageType, InputImageType > > RescaleFilterType; > RescaleFilterType::Pointer rescalefilter = RescaleFilterType::New(); > rescalefilter->SetInput( reader->GetOutput() ); > > typedef itk::ExtractImageFilter< InputImageType, > OutputImageType > FilterType; > FilterType::Pointer filter = FilterType::New(); > filter->InPlaceOn(); > filter->SetDirectionCollapseToSubmatrix(); > reader->UpdateOutputInformation(); > InputImageType::RegionType inputRegion = > reader->GetOutput()->GetLargestPossibleRegion(); > > InputImageType::SizeType size = inputRegion.GetSize(); > size[2] = 0; > > InputImageType::IndexType start = inputRegion.GetIndex(); > const unsigned int sliceNumber = stoi(s2);//atoi(argv[3]); > start[2] = sliceNumber; > > InputImageType::RegionType desiredRegion; > desiredRegion.SetSize( size ); > desiredRegion.SetIndex( start ); > > filter->SetExtractionRegion( desiredRegion ); > > filter->SetInput( rescalefilter->GetOutput() ); > writer->SetInput( filter->GetOutput() ); > try > { > writer->Update(); > } > catch( itk::ExceptionObject & err ) > { > std::cerr << "ExceptionObject caught !" << std::endl; > std::cerr << err << std::endl; > getchar(); > return EXIT_FAILURE; > } > } > return EXIT_SUCCESS; > } > > > > -- > Sent from: http://itk-insight-users.2283740.n2.nabble.com/ > The ITK community is transitioning from this mailing list to > discourse.itk.org. Please join us there! > ________________________________ > 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: > https://itk.org/mailman/listinfo/insight-users > --000000000000da2a50058864589b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon= t-family:verdana,sans-serif;font-size:small">Definitions of=C2=A0<span styl= e=3D"font-family:monospace,monospace">RescaleFilterType</span>=C2=A0and=C2= =A0<span style=3D"font-family:monospace,monospace">FilterType</span>=C2=A0s= hould be like this:</div><div class=3D"gmail_default" style=3D"font-family:= verdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" = style=3D"font-size:small"><div class=3D"gmail_default" style=3D""><font fac= e=3D"monospace, monospace">typedef itk::RescaleIntensityImageFilter< Inp= utImageType, OutputImageType > RescaleFilterType;</font></div><div class= =3D"gmail_default" style=3D""><font face=3D"monospace, monospace">typedef i= tk::ExtractImageFilter< OutputImageType, OutputImageType > FilterType= ;</font></div></div></div></div><br><div class=3D"gmail_quote"><div dir=3D"= ltr" class=3D"gmail_attr">On Wed, May 8, 2019 at 1:54 PM Shrabani Ghosh <= ;<a href=3D"mailto:[email protected]">[email protected]</a>> w= rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p= x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I did it l= ike this and I am getting images like this now. <br> <<a href=3D"http://itk-insight-users.2283740.n2.nabble.com/file/t396636/= slice1.png" rel=3D"noreferrer" target=3D"_blank">http://itk-insight-users.2= 283740.n2.nabble.com/file/t396636/slice1.png</a>> <br> <br> <br> <br> int main( int argc, char ** argv )<br> {<br> <br> =C2=A0 //typedef signed short=C2=A0 =C2=A0 =C2=A0 =C2=A0 InputPixelType;<br= > =C2=A0 /*typedef unsigned char=C2=A0 =C2=A0 =C2=A0 =C2=A0InputPixelType;<br= > =C2=A0 typedef unsigned char=C2=A0 =C2=A0 =C2=A0 =C2=A0 OutputPixelType;*/<= br> =C2=A0 typedef signed short=C2=A0 =C2=A0 =C2=A0 =C2=A0InputPixelType;<br> =C2=A0 typedef unsigned char=C2=A0 =C2=A0 =C2=A0 OutputPixelType;<br> =C2=A0 typedef itk::Image< InputPixelType,=C2=A0 3 >=C2=A0 =C2=A0 Inp= utImageType;<br> =C2=A0 typedef itk::Image< OutputPixelType, 2 >=C2=A0 =C2=A0 OutputIm= ageType;<br> =C2=A0 typedef itk::ImageFileReader< InputImageType=C2=A0 >=C2=A0 Rea= derType;<br> =C2=A0 typedef itk::ImageFileWriter< OutputImageType >=C2=A0 WriterTy= pe;<br> =C2=A0 const char * inputFilename=C2=A0 =3D "G:/My Drive/BMES2019/New<= br> folder/subject1.nii";<br> <br> =C2=A0 {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int i =3D 1;<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 std::string str=3D"input//";<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 std::string s1=3D"slice";<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 std::string s2 =3D std::to_string(i);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 std::string s3=3D".png";<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 std::string s4=3Dstr+s1+s2+s3;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 const char *mycharp =3D s4.c_str();<br> <br> =C2=A0 const char * outputFilename =3D mycharp;<br> <br> =C2=A0 ReaderType::Pointer reader =3D ReaderType::New();<br> =C2=A0 WriterType::Pointer writer =3D WriterType::New();<br> <br> =C2=A0 reader->SetFileName( inputFilename=C2=A0 );<br> =C2=A0 writer->SetFileName( outputFilename );<br> <br> =C2=A0 =C2=A0typedef itk::RescaleIntensityImageFilter< InputImageType, I= nputImageType<br> > RescaleFilterType;<br> =C2=A0 =C2=A0RescaleFilterType::Pointer rescalefilter =3D RescaleFilterType= ::New();<br> =C2=A0 =C2=A0rescalefilter->SetInput( reader->GetOutput() );<br> <br> =C2=A0 typedef itk::ExtractImageFilter< InputImageType,<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0OutputImageType > Fi= lterType;<br> =C2=A0 FilterType::Pointer filter =3D FilterType::New();<br> =C2=A0 filter->InPlaceOn();<br> =C2=A0 filter->SetDirectionCollapseToSubmatrix();<br> =C2=A0 =C2=A0reader->UpdateOutputInformation();<br> =C2=A0 InputImageType::RegionType inputRegion =3D<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0reader->GetOutput()->GetLarg= estPossibleRegion();<br> <br> =C2=A0 InputImageType::SizeType size =3D inputRegion.GetSize();<br> =C2=A0 size[2] =3D 0;<br> <br> =C2=A0 InputImageType::IndexType start =3D inputRegion.GetIndex();<br> =C2=A0 const unsigned int sliceNumber =3D stoi(s2);//atoi(argv[3]);<br> =C2=A0 start[2] =3D sliceNumber;<br> <br> =C2=A0 InputImageType::RegionType desiredRegion;<br> =C2=A0 desiredRegion.SetSize(=C2=A0 size=C2=A0 );<br> =C2=A0 desiredRegion.SetIndex( start );<br> <br> =C2=A0 filter->SetExtractionRegion( desiredRegion );<br> <br> =C2=A0 filter->SetInput( rescalefilter->GetOutput() );<br> =C2=A0 writer->SetInput( filter->GetOutput() );<br> =C2=A0 =C2=A0try<br> =C2=A0 =C2=A0 {<br> =C2=A0 =C2=A0 writer->Update();<br> =C2=A0 =C2=A0 }<br> =C2=A0 catch( itk::ExceptionObject & err )<br> =C2=A0 =C2=A0 {<br> =C2=A0 =C2=A0 std::cerr << "ExceptionObject caught !" <&= lt; std::endl;<br> =C2=A0 =C2=A0 std::cerr << err << std::endl;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 getchar();<br> =C2=A0 =C2=A0 return EXIT_FAILURE;<br> =C2=A0 =C2=A0 }<br> =C2=A0 =C2=A0 }<br> =C2=A0 return EXIT_SUCCESS;<br> }<br> <br> <br> <br> --<br> Sent from: <a href=3D"http://itk-insight-users.2283740.n2.nabble.com/" rel= =3D"noreferrer" target=3D"_blank">http://itk-insight-users.2283740.n2.nabbl= e.com/</a><br> The ITK community is transitioning from this mailing list to <a href=3D"htt= p://discourse.itk.org" rel=3D"noreferrer" target=3D"_blank">discourse.itk.o= rg</a>. Please join us there!<br> ________________________________<br> Powered by <a href=3D"http://www.kitware.com" rel=3D"noreferrer" target=3D"= _blank">www.kitware.com</a><br> <br> Visit other Kitware open-source projects at<br> <a href=3D"http://www.kitware.com/opensource/opensource.html" rel=3D"norefe= rrer" target=3D"_blank">http://www.kitware.com/opensource/opensource.html</= a><br> <br> Kitware offers ITK Training Courses, for more information visit:<br> <a href=3D"http://www.kitware.com/products/protraining.php" rel=3D"noreferr= er" target=3D"_blank">http://www.kitware.com/products/protraining.php</a><b= r> <br> Please keep messages on-topic and check the ITK FAQ at:<br> <a href=3D"http://www.itk.org/Wiki/ITK_FAQ" rel=3D"noreferrer" target=3D"_b= lank">http://www.itk.org/Wiki/ITK_FAQ</a><br> <br> Follow this link to subscribe/unsubscribe:<br> <a href=3D"https://itk.org/mailman/listinfo/insight-users" rel=3D"noreferre= r" target=3D"_blank">https://itk.org/mailman/listinfo/insight-users</a><br> </blockquote></div> --000000000000da2a50058864589b-- --===============1942928187== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there! ________________________________ 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: https://itk.org/mailman/listinfo/insight-users --===============1942928187==--