Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Image conversion help
#1
Hi all,

I am trying to converst a series of float32 2D tif images to uint16 images and the read them into a 3D array. I can run the full code to get a float32 array output (float32 in ln1 below, no ln8), but when I try and do the conversion (either before the tif is added to the array as shpwn below, or after the array is created) I get a uint16 array of zeros. I have tried:

  data=numpy.zeros((init.shape[1],init.shape[0],height),dtype=numpy.uint16)
                    del init
                    for j in range(0,height):
                        if selection == 0:
                            image=numpy.swapaxes(numpy.array(Image.open('rec_'+str(j).zfill(5)+'.tif')),0,1)
                        elif selection == 1:
                            image=numpy.swapaxes(numpy.array(Image.open(first.replace('0001',str(j+1).zfill(4)))),0,1)
                            image=ImageMath.eval("(a+b)*(c)", a=image, b=0.001, c=15000000)  #arbitrary values here for illustration
                            image = numpy.rint(image) 


and

  data=numpy.zeros((init.shape[1],init.shape[0],height),dtype=numpy.uint16)
                    del init
                    for j in range(0,height):
                        if selection == 0:
                            image=numpy.swapaxes(numpy.array(Image.open('rec_'+str(j).zfill(5)+'.tif')),0,1)
                        elif selection == 1:
                            image=numpy.swapaxes(numpy.array(Image.open(first.replace('0001',str(j+1).zfill(4)))),0,1)
                            image=skimage.img_as_uint(image)                         
                            data[:,:,j]=image 
and

  data=numpy.zeros((init.shape[1],init.shape[0],height),dtype=numpy.uint16)
                    del init
                    for j in range(0,height):
                        if selection == 0:
                            image=numpy.swapaxes(numpy.array(Image.open('rec_'+str(j).zfill(5)+'.tif')),0,1)
                        elif selection == 1:
                            image=numpy.swapaxes(numpy.array(Image.open(first.replace('0001',str(j+1).zfill(4)))),0,1)
                            image = exposure.rescale_intensity(image, in_range='float32', out_range=(0,2))
                            image=skimage.img_as_uint(image)                         
                            data[:,:,j]=image 
in case it was the scaing from unsigned to signed that was causing the data to be cropped (althouth my data are int positive part of the range). But I still get zeros. I am a coding novice and am not sure why I can;t get the greyscale output I should. I am hopig somwone can explain what I am doing wrong.

Help much appreciated!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Image conversion form cartesian to polar and back to cartesian Ashwinraj 2 16,333 Aug-10-2017, 09:01 AM
Last Post: Ashwinraj

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020