how to convert image values into pixels and viceversa

3 ビュー (過去 30 日間)
srinath g
srinath g 2019 年 2 月 24 日
回答済み: Dev 2025 年 2 月 26 日
how to obtain 2d matrix from a image and recover image from pixels

回答 (1 件)

Dev
Dev 2025 年 2 月 26 日
Since you aim to obtain a 2D matrix from an image, I am assuming that you are working with grayscale images. We can first read the image file using the ‘imread’ function in MATLAB. More information on the same can be referred below-
In case the image is coloured (RGB), we can convert the same to a grayscale image using the ‘rgb2gray’ function in MATLAB. More details on this function can be referred below-
Next, we can use the below code to read it into a 2D matrix-
% 2D matrix representing the image
matrix_2d = double(image);
The grayscale image pixel data is stored in ‘matrix_2d’ and the image can be recovered from this data using the ‘mat2gray’ MATLAB function. More information on the same can be referred to below-
I hope this is solves the purpose.

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by