[Rtk-users] get simpleRTK image from array

Simon Rit simon.rit at creatis.insa-lyon.fr
Tue Apr 18 13:31:36 CEST 2017


Hi,
You need to work with numpy, as explained in the help:

>>> import SimpleRTK as srtk
>>> help(srtk.GetImageFromArray)
Help on function GetImageFromArray in module SimpleRTK.SimpleRTK:

GetImageFromArray(arr, isVector=False)
    Get a SimpleRTK Image from a numpy array. If isVector is True, then a
3D array will be treaded as a 2D vector image, otherwise it will be treaded
as a 3D image

So in this example, you can obtain what you want by adding
import SimpleRTK as srtk

at the beginning and then doing
a = srtk.GetArrayFromImage(reiImage)
b = (0.00000000018308 * np.power(a, 4)) - (0.000000117480729 * np.power(a,
3)) + (0.00001747041637 * np.power(a, 2)) + 1.000021291118193 * a
reiImage = srtk.GetImageFromArray(a)

This should work.
Simon

On Tue, Apr 18, 2017 at 9:23 AM, sare Borhani <sareh.borhani at gmail.com>
wrote:

> Dear RTK.User,
>
> I'm using python wrapped version of RTK.
>
> I used the only example of that for reconstruction.It works perfectly.
> The problem is that I need to simulate an artifact on projection 2D
> images, so first I got each 2D images of stack reiImage by
> *srtk.GetArrayFromImage(reiImage) *and then I applied a polynomial on
> that to simulate an artifact.NOW need to extract these artifacted-images
> again to the simpleRTK image to be able to reconstruct it at the end. I
> thought maybe *srtk.GetImageFromArray* works, but it doesn't.
>
> rei.SetAxis(semiprincipalaxis)
> rei.SetGeometry( geometry )
> reiImage = rei.Execute(source)
>
> sampleList = []
> for rcount in range(0,127):
>     outputName = '/home/PycharmProjects/test/Sample'+ str(rcount)
>     #plt.imsave(outputName, srtk.GetArrayFromImage(reiImage [:,rcount,:]),  cmap='gray')
>     sampleList.append(srtk.GetArrayFromImage(reiImage [:,rcount,:]))
>
> test = np.zeros(np.shape(sampleList[0]),dtype=np.float32)
>
> bhImages = []
> for reiImage1 in sampleList:
>     #img = plt.imread('/home/PycharmProjects/reiOutput/Sample%d'%k)
>     #modifiedImg = sampleList[k]
>     artifactedreiImg= np.zeros(np.shape(reiImage1),dtype=np.float32)
>     for i in range (reiImage1.shape[0]):
>         for j in range (reiImage1.shape[1]):
>             a = reiImage1[i, j]
>             b = (0.00000000018308 * pow(a, 4)) - (0.000000117480729 * pow(a, 3)) + (0.00001747041637 * pow(a, 2)) + 1.000021291118193 * a
>
>             artifactedreiImg[i, j] = b
>
>     artifactedreiImg = artifactedreiImg.astype(np.float32)
>
>     bhImages.append(artifactedreiImg.astype(np.float32))
>     #plt.imsave(outputName, artifactedreiImg, cmap='gray')
>
>
> *for i,artifactedImage in enumerate(bhImages): bhImage[:,i,:]= srtk.GetImageFromArray(artifactedImage[:,:])*
>
> in last lines I tried to get the stack of artifacted images like reiImage and then paste bhImage instead of reiImage for the reconstruction part. But I got this eror message:TypeError: 'tuple' object does not support item assignment
>
> First I tried to change the reiImage but it seems its unwritable.
>
> Best regards,
> Sareh Borhani
>
> _______________________________________________
> Rtk-users mailing list
> Rtk-users at public.kitware.com
> http://public.kitware.com/mailman/listinfo/rtk-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/rtk-users/attachments/20170418/15e4ccc4/attachment.htm>


More information about the Rtk-users mailing list