We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When a file is corrupted, libpng generates an error and it is not caught.
See for example https://stackoverflow.com/questions/46683264/libpng-error-read-error-by-using-open-cv-imread or https://stackoverflow.com/questions/70598227/libpng-error-read-error-why-cant-this-image-be-processed-by-opencv
Following the advice found on the second link, I rewrote this part (maybe In case of rgb images: make gray images compatible with RGB is unnecessary):
`
def _imread(filepath, colorscale=1): """Read image from filepath using colour-scaling.
Parameters ---------- filepath : str path to file. colorscale : int, default: 1 (gray) colour-scaling from opencv. * 0: cv2.IMREAD_GRAYSCALE * 1: cv2.IMREAD_COLOR * 8: cv2.COLOR_GRAY2RGB Returns ------- img : numpy array raw rgb or gray image. """ img=None # if os.path.isfile(filepath): # Read the image # img = cv2.imread(, colorscale) img = Image.open(filepath) # Convert Image to numpy array # It's not the most efficient way, but it works. *(link¹) img = np.asarray(img) # Remove alpha channel if existent if len(img.shape) == 3 and img.shape[2] == 4: img = img[:, :, : 3] # Restore RGB colors img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # In case of rgb images: make gray images compatible with RGB if ((colorscale!=0) and (colorscale!=6)) and (len(img.shape)<3): img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) # else: # logger.warning('File does not exists: %s', filepath) return cv2.cvtColor(img, colorscale)`
The text was updated successfully, but these errors were encountered:
Thank you for directly providing this solution! I added this function. Update with: pip install -U clustimage
pip install -U clustimage
Sorry, something went wrong.
No branches or pull requests
When a file is corrupted, libpng generates an error and it is not caught.
See for example https://stackoverflow.com/questions/46683264/libpng-error-read-error-by-using-open-cv-imread or https://stackoverflow.com/questions/70598227/libpng-error-read-error-why-cant-this-image-be-processed-by-opencv
Following the advice found on the second link, I rewrote this part (maybe In case of rgb images: make gray images compatible with RGB is unnecessary):
`
%% Read image
def _imread(filepath, colorscale=1):
"""Read image from filepath using colour-scaling.
The text was updated successfully, but these errors were encountered: