Azure Computer Vision background removal is changing jpg's to png internally

Neil Thompson 20 Reputation points
2024-11-28T10:13:40.6066667+00:00

Azure Computer Vision background removal is changing jpg's to png internally. This is causing us a problem as our storefront provider (Oracle) rejects images where the mime type does not match the extension.

To reproduce:

Start with a jpg image

perform background removal using the Computer vision service

inspect the metadata ... your jpg is now a png with a jpg extension, eg:

file_name: HD_300013924.cb10ee53-65ee-4dba-a2bc-dcd0cc29a3db**.jpg**

file_size: 232 kB

file_type: PNG

file_type_extension: png

mime_type: image/png

Can I get the computer vision service to respect the original file type? Is the issue transparency? Thank you

Azure Computer Vision
Azure Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
396 questions
0 comments No comments
{count} votes

Accepted answer
  1. Azar 24,685 Reputation points MVP
    2024-11-28T14:52:50.15+00:00

    Hi there Neil Thompson

    Thanks for using the QandA platform

    Guess this this is because PNG supports transparency, which is necessary when removing backgrounds, JPEG does not support transparent pixels. so, the image metadata is changed to reflect the PNG format, though the file extension remains .jpg, causing the mismatch with the MIME type and file extension expected by your storefront provider.

    So, you can either post-process the image after background removal, using any tools like else a server-side script, to convert the PNG back to JPEG,

    The issue is indeed related to transparency, as the PNG format is necessary for handling images with transparent areas. If transparency is not required in your use case, post-processing to convert the image back to JPEG after background removal is likely the best do.

    If this helps kindly accept the answer thanks much.


1 additional answer

Sort by: Most helpful
  1. SriLakshmi C 1,375 Reputation points Microsoft Vendor
    2024-11-28T16:43:25.37+00:00

    Hello Neil Thompson,

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Thank you for bringing this to our attention. The issue with Azure Computer Vision's background removal changing JPG images to PNG format stems from the service’s handling of transparency. When the background is removed, the resulting image may include transparent areas, which the JPG format does not support. To address this, the service converts the image to PNG format, as PNG supports transparency. However, this conversion retains the original .jpg file extension, causing a mismatch between the file type and its MIME type, which can lead to compatibility issues with systems that require alignment between the two.

    I attempted to reproduce this scenario in my environment, and while the behavior cannot be directly altered through the service, it is possible to manually save the image using a JPG extension, ensuring proper compatibility. If you continue to experience issues or require further assistance, please feel free to let us know.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.