Reputation: 461
I am trying to read an image using skimage package, then crop it and then save it. Till cropping it works fine. While saving, it throws the below error
ValueError: Could not find a format to write the specified file in single-image mode
Below is my code. Any help is highly appreciated. thanks
import os
import numpy as np
import matplotlib.pyplot as plt
import skimage
import dataloader
from utility import To_csv
path='D:\\beantech_Data\\objtect_detection'
def crop(img):
return skimage.util.crop(img, ((0,500),(0,0),(0,0)))
images, boxes, labels = dataloader.train_loader(path)
os.makedirs(os.path.join(path, 'train','cropped'), exist_ok=True)
for i in range(len(images)):
croped_image = crop(images[i])
skimage.io.imsave(os.path.join(path, 'train','cropped',f'img{str(i)}'), croped_image)
box = boxes[i]
To_csv(box, i,os.path.join(path, 'train','cropped'), Aug= True )
Upvotes: 2
Views: 5023
Reputation: 461
The problem is, no file format is given in the code i.e. (.png, .jpeg etc).
By correcting this line the code works fine-
skimage.io.imsave(os.path.join(path, 'train','cropped',f'img{str(i)}.png'), croped_image)
thanks
Upvotes: 2