0

(First time user)

I want to read tif files from a folder.

N=22 (the number of tif files in the folder)

The name of the folder is: tif_files

The file names start at E_0 and ends at E_21

I'm reading the folder using:

for i in range(N):
 im = imageio.imread(path + tifFiles[i])

I get N from:

N = len(tifFiles)

which gives me 22


I get tifFiles using:

tifFiles = sorted([f for f in listdir(path) if isfile(join(path, f))])

The path is: '/Users/name/rsm/tif_files/'


print(im.shape) gives me (514, 1030, 4) {I'm expecting it to be (514 1030 22)}


If I print the output list of the files (tifFiles) it gives me the 22 files:

print(tifFiles)

['E_0.tif', 'E_1.tif', 'E_10.tif', 'E_11.tif', 'E_12.tif', 'E_13.tif', 'E_14.tif', 'E_15.tif', 'E_16.tif', 'E_17.tif', 'E_18.tif', 'E_19.tif', 'E_2.tif', 'E_20.tif', 'E_21.tif', 'E_3.tif', 'E_4.tif', 'E_5.tif', 'E_6.tif', 'E_7.tif', 'E_8.tif', 'E_9.tif']


I put all of this in a function:

function(path,filename)

note: filename is used further downstream in the function to describe the output files of the images


  1. I made sure that I'm in the right path (not reading from somewhere else).
  2. I tried using tiff files instead of tif files.
  3. I changed the files names from "E_0" to "E0" to discard the use of the underscore

So I have to get 22 arrays of (514 1030) pixels but I'm getting only 4.

  • 1
    You are assigning each individual image to `im`, overwriting the previous image. You're left only with the last image - 515 by 1030 pixels, by 4 components (presumably R, G, B, alpha). – jasonharper Aug 29 '23 at 14:02
  • If I read this right, your loop is overriding "im" every time, so the result is what you get, with the 3rd dimension of size 4 for RGB and alpha (or whatever color palette you're using). EDIT: @jasonharper bet me by 30sec :D – André Aug 29 '23 at 14:03
  • @jasonharper Jason Harper and André: Yes, both of you are correct. The .tif file contains four channels per pixel. I converted the files to grayscale images and the code ran fine. My next step will be to make code to convert files (a lot of files) on Python instead of using external software. I don't see an upvote arrow to upvote you guys. – Photons are fun Aug 30 '23 at 14:11

0 Answers0