0

I have a lot of jpeg images stored on my hard drive that I would like to read and convert to arrays using skimage.io.imread

I would like to be able to do something like this:

import os
from skimage import io

os.chdir('C:/Users/HP User/Desktop/')

img = io.imread('filename.jpg')

When I run it I get the error message:

No such file or directory: 'C:/Users/HP User/Desktop/'
Scott Mermelstein
  • 15,174
  • 4
  • 48
  • 76
Joe
  • 1
  • Are you sure the directory actually exists? Not only `os` supports your code normally, but I also ran your exact code in my machine and everything worked as expected – Rodolfo Donã Hosp Jun 25 '19 at 14:25
  • It definitely does exist. I'm cutting and pasting the path from the "properties" menu of the image file (changing the backslashes to forward slashes). – Joe Jun 25 '19 at 15:20
  • 1
    The error message is definitely on the `chdir`, not on the `io.imread`. For some reason, it's not finding the directory you're giving to chdir. Try avoiding the issue, and simply putting the one line: `img = io.imread('C:/Users/HP User/Desktop/filename.jpg')`. You _may_ get a different response. (Or, you may get the exact same issue.) – Scott Mermelstein Jun 25 '19 at 16:15
  • Also try to check if your script isn't beeing permission denied by OS (although It's pretty unlikely since we are dealing with Desktop itself) – Rodolfo Donã Hosp Jun 25 '19 at 17:11
  • Thanks for the suggestions, but still no luck. – Joe Jun 26 '19 at 00:54
  • So, I think it's an issue with using Google Colab. I just tried everything using Jupyter Notebook, and it worked just fine. In Colab, the default working directory is the mysterious '/content', and I can't change it. I'd still like to use Colab, though. Any ideas? – Joe Jun 26 '19 at 01:22
  • Colab notebooks run on a web server, not on your machine. So you need to upload your data to that server to access it. This question might be the one you need: https://stackoverflow.com/questions/46986398/import-data-into-google-colaboratory – Juan Jun 26 '19 at 07:24
  • Thanks. Mounting my Google drive or using ```files.upload()``` are workable, and I've been doing that. I'd much rather avoid the upload widget or my Google drive and just do it the way I indicated above. If this functionality is missing from Colab, it seems like a big omission. For now, I'll use the workarounds. Thanks for all the tips! – Joe Jun 26 '19 at 14:14

0 Answers0