-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
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
Slicing: Quality focused default image format selection and jpg quality #956
Conversation
- add suffix default extension selection based on input images data format quality
Interesting finding! Perhaps the Or why not use the |
Thanks for pointing that out! I changed the quality parameter accordingly (quality='keep') |
@jokober @bertrandchauveau thanks a lot for your valuable discussion! Once the tests pass, we can merge 👍 |
@@ -317,7 +317,7 @@ def _export_single_slice(image: np.ndarray, output_dir: str, slice_file_name: st | |||
image_pil = read_image_as_pil(image) | |||
slice_file_path = str(Path(output_dir) / slice_file_name) | |||
# export sliced image | |||
image_pil.save(slice_file_path) | |||
image_pil.save(slice_file_path, quality="keep") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI using quality="keep"
fails (silently) for jpg ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @fcakyon - I'd raise an issue but these don't seem to be available on this repo. I'd probably try/except the code executed in the thread pool too, just so we don't silently fail again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the hint. Can you try with following line (only for jpegs)?
image_pil.save(slice_file_path, 'JPEG', quality="keep")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just deleted the quality parameter to make it work = ) It looks like it won't work as this still errors for me.
from PIL import Image
Image.new("RGB", (100, 100)).save("tmp.jpg", "JPEG", quality="keep")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh from above:
According to the pillow documentation: "The value keep is only valid for JPEG files and will retain the original image quality level, subsampling, and qtables."
The problem is these aren't JPG files, these are slices of numpy arrays or similar, so I don't think anything will be kept. Maybe just revert to the quality argument you had?
Out of interest, do you have any examples of the poorer quality - both visual, but also the impact on model performance? As far as I can tell, converting a JPEG (which already has the compression artifacts etc.) into PNG gains very little, but loses a lot in terms of disk speed and performance - PNG is obviously a lot bigger, but also a lot slower to encode/decode (especially for PIL in one of my tests a while back). Even if the re-compression adds a few more artifacts, IIRC there are papers showing a bunch of computer vision is relatively robust to this - though that might not be for small objects. Anyway, for 99% of use cases, this seems like it will harm most users - especially when there's already the For context, I ended up in the 99%. I've got 32gb of 4k JPEG and I noticed that the tiled image directory was getting massive. (I think it would have ended up something like 300gb, but I killed it before I could test that.) Hence how I ended up here - specifying PS - you should totally look into QOI if you want lossless without the CPU/disk bottlenecking that can come from using PNG (assuming you've got a decent GPU) ...
|
Image quality is important in the domain of small object detection. i think the default behavior of SAHI could be more focused on image quality. let me explain why:
I realized two things
Both together intruduces image quality reduction due to slicing.
I propose two changes