How can i upload this raw format image in the matlab?
1 次查看(过去 30 天)
显示 更早的评论
Hello guys,
How to upload the PNG file and convert it JPEG format
Thanks a lot
Devyani
回答(1 个)
Sulaymon Eshkabilov
2023-12-30
These are common procedures:
(1) Image import / read by MATLAB: imread()
(2) Image export in whatever format: imwrite() or saveas()
% (1) Import
ABC = imread('BMW.png'); figure; imshow(ABC)
% (2) Export
imwrite(ABC,'A_BMW.jpg','jpg');
1 个评论
DGM
2023-12-30
编辑:DGM
2023-12-30
While imread()/imwrite() would indeed be the preferred route, there are a few things to consider -- both in general, and in this specific case.
If you ever intend to subsequently process the images for any technical purpose (other than studying lossy compression), you shouldn't be writing them to JPG. Depending on the content, converting a PNG to baseline JPG will result in possibly significant and definitely permanent loss of information, in many cases resulting in a damaged image which occupies more space for no practical benefit. Things which can be expressed in a PNG (e.g. indexed color and alpha) will necessarily be lost, since they can't be expressed in JPG.
If you're just trying to use MATLAB to convert some photos because you're more familiar with MATLAB than automation of other image editing or conversion software, you still probably shouldn't be doing it with MATLAB. Whether it's with imwite() or any roundabout destructive workflow involving figure capture, the JPG that you'll get is at 75% quality (default, but might be adjustable depending on the usage) and 4:2:0 chroma subsampling (not configurable). That's much lower quality than the default settings you might expect from most other grahpics software. If you're used to using JPG in Photoshop or GIMP, you won't get what you expect.
Consider the following test set. The first image was saved as a PNG. The second image was saved using GIMP defaults for JPG (90%, no subsampling). The third image was saved using MATLAB defaults for JPG. The three were concatenated and upscaled 5x for viewing purposes. The differences are not subtle, and for this content, both JPG files are larger than the clean PNG.
Now to the specifics of this case, the image appears to have transparency, but if we are so bold as to expect that it does, we get an error:
Error using imread (line 432)
Too many output arguments.
Error in AT_sandbox (line 9)
[inpict,~,alph] = imread('BMW.png');
That's valid syntax. Why do we get an error?
The answer is both simple and infuriatingly commonplace on the web now. The file is a fake PNG. It doesn't have any transparency. It's not even a PNG file. We don't need to convert it to a JPG, because it already is a JPG.
$ exiftool BMW.png
ExifTool Version Number : 9.46
File Name : BMW.png
Directory : .
File Size : 160 kB
File Modification Date/Time : 2023:12:30 05:07:45-06:00
File Access Date/Time : 2023:12:30 05:08:15-06:00
File Inode Change Date/Time : 2023:12:30 05:07:45-06:00
File Permissions : rw-r--r--
File Type : JPEG
MIME Type : image/jpeg
JFIF Version : 1.01
Resolution Unit : None
X Resolution : 1
Y Resolution : 1
Image Width : 840
Image Height : 585
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Image Size : 840x585
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!