def pil_to_skimage(img):
"""
Convert PIL image to a Skimage image
:param img: PIL image object
:return: Skimage image object
"""
# Get the absolute path of the working directory
abspath = os.path.dirname(__file__)
# Create a temp file to store the image
temp = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False, dir=abspath)
# Save the image into the temp file
img.save(temp.name, 'JPEG')
# Read the image as a SciKit image object
ski_img = io.imread(temp.name, plugin='pil')
# Close the file
temp.close()
# Delete the file
os.remove(temp.name)
return ski_img
评论列表
文章目录