Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load JPEG from URL to skimage without temporary file

Is it possible to load image in skimage (numpy matrix) format from URL without creating temporary file?

skimage itself uses temporary files: https://github.com/scikit-image/scikit-image/blob/master/skimage/io/util.py#L23

Is there any way to pass urlopen(url).read() to imread.imread() (or any other image reading library) directly?

like image 801
user1263702 Avatar asked Aug 27 '15 08:08

user1263702


2 Answers

From imread documentation:

Image file name, e.g. test.jpg or URL

So you can directly pass your URL:

io.imread(url)

Notice that it will still create a temporary file for processing the image...


Edit:

The library imread also have a method imread_from_blob which accept a string as input. So you may pass your data directly to this function.

from imread import imread_from_blob
img_data = imread_from_blob(data, 'jpg')

>>> img_data
array([[[ 23, 123, 149],
[ 22, 120, 147],
[ 22, 118, 143],
...,

The second parameter is the extension typically associated with this blob. If None is given, then detect_format is used to auto-detect.

like image 145
Cyrbil Avatar answered Oct 04 '22 23:10

Cyrbil


import matplotlib.pyplot  as plt
from skimage import io

image=io.imread ('https://i.stack.imgur.com/yt0Xo.jpg')

plt.imshow(image)
plt.show()
like image 35
Mahmoud Avatar answered Oct 04 '22 22:10

Mahmoud