biolab / orange3-imageanalytics

🍊 :rice_scene: Orange3 add-on for dealing with image related tasks
GNU General Public License v3.0
32 stars 42 forks source link

[ENH] Import Images: Add bmp other QImageReader supported formats #208

Closed lanzagar closed 2 years ago

lanzagar commented 2 years ago
Issue

The Import Images widget did not support loading .bmp image files.

Description of changes

Add support for BMP and other formats supported by QImageReader. In this PR we remove the hardcoded list of all available formats. Supported formats are now limited only to formats supported by QImageReader (before we limited formats with a predefined list of supported extensions and QImageReader).

Includes
codecov[bot] commented 2 years ago

Codecov Report

Merging #208 (607cf3a) into master (a3e7785) will increase coverage by 0.11%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
+ Coverage   68.97%   69.08%   +0.11%     
==========================================
  Files          17       17              
  Lines        2830     2834       +4     
  Branches      434      436       +2     
==========================================
+ Hits         1952     1958       +6     
+ Misses        769      768       -1     
+ Partials      109      108       -1     
PrimozGodec commented 2 years ago

There is a possibility of getting the set of all supported formats from Pillow:

from PIL import Image

exts = Image.registered_extensions()
supported_extensions = {ex for ex, f in exts.items() if f in Image.OPEN}

The discussion I opened is here: https://stackoverflow.com/questions/71112986/retrieve-a-list-of-supported-read-file-extensions-formats/71114152#71114152

PrimozGodec commented 2 years ago

I added the list of all PIL supported formats (which is vast), but then I realized that whether the image can be open or not is checked by QImageReader, which supports the following formats.

ImageEmbedder uses PIL to load images, but Image Viewer and Image Grid use QImageReader to load images to show in the widget. Anyway, the list was missing BMP, which Qt also supports.

So we have two options here:

  1. support all Pillow supported formats -- it means some extra work to make other widgets load images that QImageReader does not support
  2. support only QImageReader supported formats -- it is closer to what is supported now

If we decide on the latest, I suggest deprecating the formats attribute of the ImportImages class and removing the DefaultFormats list and only checking whether an image can be open QImageReader.

PrimozGodec commented 2 years ago

@lanzagar, it is ready for review. The test that is failing were failing before already and does not have anything to do with changes