0

I would like to cut my code into chunk so I don't have to run everything at once. Can someone point me in the direction as to why this works:

from skimage import io
import numpy as np
    
filename = input("Enter file name\n")
img = io.imread(f"images/{filename}.tif", as_gray=True)
img = np.array(img).astype(np.float32)

but this doesn't work?

from skimage import io
import numpy as np

def loadfile():
    filename = input("Enter file name\n")
    img = io.imread(f"images/{filename}.tif", as_gray=True)
    img = np.array(img).astype(np.float32)
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Innuendo
  • 33
  • 4
  • Can you clarify `this doesn't work`? E.g. it looks like you are not calling the function `loadfile` at all. – FlyingTeller Apr 25 '22 at 14:20
  • 1
    Well, the second version defines a function that never gets called - and doesn't return the loaded image, so it would be useless even if it was called. – jasonharper Apr 25 '22 at 14:21
  • 1
    So it's not really related to skimage at all.... – jtlz2 Apr 25 '22 at 14:23
  • 1
    @jtlz2, I think I just rolled back a formatting edit you made. _Either_ triple-backtick lines _or_ four-space indents should be used for code formatting, not both at once -- see how starting from revision 2 the code was excessively indented. – Charles Duffy Oct 01 '22 at 18:29

0 Answers0