I see, ArrayFromImage really wants an itk.Image (unlike ITK filters for which inheritance seems to work). Then you can just do the same trick as when converting from CPU to GPU image: feldkamp.Update() fdk = CPUImageType.New() fdk.SetPixelContainer(feldkamp.GetOutput().GetPixelContainer()) fdk.CopyInformation(feldkamp.GetOutput()) fdk.SetBufferedRegion(feldkamp.GetOutput().GetBufferedRegion()) fdk.SetRequestedRegion(feldkamp.GetOutput().GetRequestedRegion()) itk.array_from_image(fdk)
PS: I won't answer next time if you don't use the mailing list.... On Mon, Nov 27, 2023 at 8:18 AM Fuquan Deng <[email protected]> wrote: > # 重建 > feldkamp = rtk.CudaFDKConeBeamReconstructionFilter.New() > feldkamp.SetInput(0, constantImageSource.GetOutput()) > feldkamp.SetInput(1, projections) > feldkamp.SetGeometry(geometry) > # feldkamp.GetRampFilter().SetTruncationCorrection(0.0) > # feldkamp.GetRampFilter().SetHannCutFrequency(0.0) > feldkamp.Update() > > # Writer > # print("Writing output image...") > # WriterType = rtk.ImageFileWriter[CPUImageType] > # writer = WriterType.New() > # writer.SetFileName(filename) > # writer.SetInput(feldkamp.GetOutput()) > # writer.Update() > image = itk.GetArrayFromImage(feldkamp.GetOutput()) > return image > > Traceback (most recent call last): > > File "/home/ctwork/workstation/ctwork/completeRAC/reconstruct.py", line > 108, in <module> > > reconstruction(image, geoFile, spacing=spacing, spacingOut=0.14, > sizeOutput=1024,filename="temp1.mhd") > > File "/home/ctwork/workstation/ctwork/completeRAC/reconstruct.py", line > 71, in reconstruction > > image = itk.GetArrayFromImage(feldkamp.GetOutput()) > > File > "/home/ctwork/software/anaconda3/lib/python3.9/site-packages/itk/support/extras.py", > line 335, in GetArrayFromImage > > return _GetArrayFromImage( > > File > "/home/ctwork/software/anaconda3/lib/python3.9/site-packages/itk/support/extras.py", > line 314, in _GetArrayFromImage > > raise RuntimeError("No suitable template parameter can be found.") > > RuntimeError: No suitable template parameter can be found. > > > > > > > 在 2023-11-27 14:55:16,"Simon Rit" <[email protected]> 写道: > > Please stick to the mailing list. > It should, what is the error message? > > On Mon, Nov 27, 2023 at 7:53 AM Fuquan Deng <[email protected]> wrote: > >> Thanks for your answer. i convert itk.CudaImage to numpy.array after >> reconstruction by fdk. But it showed error when i use >> itk.GetArrayFromImage. Does itk not support to convert itk.CudaImage to >> numpy.array? >> >> >> >> >> At 2023-11-27 14:00:23, "Simon Rit" <[email protected]> >> wrote: >> >> Hi, >> You can find here >> <https://github.com/RTKConsortium/RTK/blob/master/examples/FirstReconstruction/FirstCudaReconstruction.py#L70-L76> >> how to convert an itk.Image to an itk.CudaImage. An itk.CudaImage is an >> itk.Image (by inheritance) so you should not need to convert it, just use >> it as if it were an itk.Image, as illustrated in the same example here >> <https://github.com/RTKConsortium/RTK/blob/master/examples/FirstReconstruction/FirstCudaReconstruction.py#L91>. >> Or have I missed something? >> Simon >> >> >> On Sun, Nov 26, 2023 at 4:06 PM Fuquan Deng <[email protected]> wrote: >> >>> Dear simon, >>> >>> althought do not the theory of transforming numpy.array to cuda image, >>> I succeed. >>> but now i have other question. >>> how to transform cudaimage to itk.Image, and then use GetArrayFromImage >>> to transform to numpy.array? >>> >>> i have read the itk and rtk documents and can not find the answer. Use >>> GPT and get wrong answer. So i come to here and send email to ask you about >>> this. Does rtk-python support this? >>> Thanks and look forward to your reply. >>> >>> Fuquan Deng >>> >>
_______________________________________________ Rtk-users mailing list [email protected] https://www.creatis.insa-lyon.fr/mailman/listinfo/rtk-users
