How to read '.webp' image file

조회 수: 66 (최근 30일)
Salad Box
Salad Box 2023년 1월 15일
편집: DGM 2024년 7월 5일
Hi,
I have a couple of image files in '.webp' format, how to read them in Matlab?

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 1월 15일
편집: KALYAN ACHARJYA 2023년 1월 15일
This option!
Save in the web & you can try using complete web path
Reference : Link
HTH
  댓글 수: 2
Salad Box
Salad Box 2023년 1월 15일
Thank you.
Image Analyst
Image Analyst 2023년 1월 16일
I don't understand. That question seems to only talk about .JPG images on the web. How would any of that work for .webp format images and get them into a variable in MATLAB?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2023년 1월 16일
Try this. Adapt as needed:
% If you enter this address
% 'https://i0.wp.com/www.bitsandpieces.us/wp-content/uploads/2023/01/unnamed-15.png?resize=600%2C334&ssl=1');
% If, in your browser, you right click, it will ask you to save the image as a .webp format file.
% But what you really want is a variable in MATLAB and from there you can save it as any file format you want.
imageURL = 'https://i0.wp.com/www.bitsandpieces.us/wp-content/uploads/2023/01/unnamed-15.png?resize=600%2C334&ssl=1';
[indexedImage, cmap] = imread(imageURL);
rgbImage = ind2rgb(indexedImage, cmap);
imshow(rgbImage);
% imwrite(rgbImage, 'Mistakes.png')
  댓글 수: 2
Sven
Sven 2023년 6월 13일
Hey IA, can you describe what's happening under the hood here?
I believe the original image is a .png but the URL suffix specifies a resize, which is done (on the server side?) using the webp format before serving that result?
Anyway, the main thing I'm coming up against is that there doesn't seem to be any native ability for MATLAB to read a .webp file stored locally. For instance, calling imread() with your provided URL works just fine, but if use your browser to save a local .webp version of the image and then provide the location of that file to imread we get the error:
>> imread(myLocalFile)
Error using imread>get_format_info
Unable to determine the file format.
I've tried providing "png" format specifier and also specifying the filename in "file:///C:/path/to/image/image.webp" format - same result.
The only way I've found to read a .webp locally is to download google's .webp processing libraries (webpd.exe for windows) and then call it from MATLAB via a system() call telling it to send the output to a temporary .png file, and then using imread() to read that resultant file. This feels clunky but maybe it's the only solution at the moment?
Anyway, just thought I'd add to the thread in case the same questions were coming up for others.
Image Analyst
Image Analyst 2023년 6월 13일
@Sven I have no idea. I know little about .webp or even why people use that instead of the original format. I didn't even know about Google's webpd.exe until you told me about it. Ask tech support if there is some better way to read .webp files.

댓글을 달려면 로그인하십시오.


DGM
DGM 2024년 7월 5일
편집: DGM 2024년 7월 5일
@Sven's workaround is still about the only thing there is. I just added a simple pair of tools to MIMT to read and write WEBP using cwebp and dwebp. There are a few conveniences added, but they're still basically just using system() calls and temp files.
% at least it's convenient
inpict = wpread('ughnotanother.webp');
Images with transparency (IA/RGBA) will be returned with attached alpha.
MIMT wpwrite() accepts I/IA/RGB/RGBA images, and defaults to lossless encoding options (-lossless and -exact in cwebp versions which support it). Something tells me though that 99% of users' interest in WEBP is trying to figure out how to make it go away, not how to create more.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by