Skip to content

improve image quality of cropped jpg files by disabling chroma subsampling #7007

@LaserBorg

Description

@LaserBorg

Search before asking

  • I have searched the YOLOv5 issues and found no similar feature requests.

Description

opencv was used to save ROI crops, but imwrite is limited at jpg quality since it uses 2x2 chroma subsampling, often reffered to as "4:2:2" (-> jpg is YUV color space) even when setting cv2.IMWRITE_JPEG_QUALITY to 100.
Quality loss is clearly visible when working on images with highly saturated colors or sharp color changes.

I propose using pillow to write jpg files, with subsampling flag set to False. It is already in the requirements and the existing numpy matrix can easily get converted to pil format.

Use case

image quality of the crops is crucial when cropped output files are further used as training data, while jpg compression still offers great benefit-cost ratio in filesize and compression speed compared to lossless (png) or even uncompressed (bmp) formats.

Additional

I have a PR ready.

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions