Hi,
is it possible to convert an JPEG file into an array in Matlab? What about the reverse conversion?
Owen

 採用された回答

Geoff Hayes
Geoff Hayes 2015 年 3 月 29 日

0 投票

Owen - when you read the JPEG image with imread the output from this function is an array. For example,
A = imread('myImg.jpg');
A is a matrix (multi-dimensional array). You can then use imwrite to save the matrix/array as a JPEG.

4 件のコメント

Image Analyst
Image Analyst 2015 年 3 月 29 日
But please don't use JPEG for image analysis unless it's absolutely unavoidable. The artifacts can severely limit your accuracy or appearance. Use a lossless format like PNG, BMP, TIFF, or JPEG2000.
Owen
Owen 2015 年 3 月 30 日
移動済み: DGM 2024 年 1 月 17 日
Thanks. It works, but there is still a problem with size matching. An JPEG file has the following parameters: 18.6KB, 242x379, but with imread() the matrix is 379x242x3 = 275154 bytes. What I expect is something around 18.6K. It seems the matrix doesn’t have the compression. So how to get the compressed matrix of an JPEG file?
Owen
Image Analyst
Image Analyst 2015 年 3 月 30 日
移動済み: DGM 2024 年 1 月 17 日
You're checking the size on disk, which will always be less. Once it's decompressed and read into a variable in your MATLAB program, it will be its full uncompressed size. To get the compressed matrix, which virtually no one ever does or ever needs to do unless you're writing your own version of imread(), then you'd have to use fread(). Of course it's not an image at that point since you'd need to decompress it.
Owen
Owen 2015 年 3 月 31 日
移動済み: DGM 2024 年 1 月 17 日
I tried fread() and it gives the 18.6KB size.
Owen

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

タグ

質問済み:

2015 年 3 月 29 日

移動済み:

DGM
2024 年 1 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by