Can an RGB image be stored as 2D matrix without converting to greyscale image?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Can an RGB image be stored as 2D matrix without converting to greyscale image in matlab?
0 commentaires
Réponses (2)
Jan
le 29 Juin 2015
You can reshape the array easily, but then it is not an image anymore in strict sense:
img = rand(640, 480, 3);
img2D = reshape(img, 640, []);
This can be reversed, but I do not see any benefit in this. It is the deeper meaning of 3D and 2D images to contain RGB values or a single channel only.
You can convert the values to uint32:
img = uint32(img(:,:,1) + img(:,:,2)*256 + img(:,:,3)*65536);
This is a 2D array also, and it contains even less memory than the double array, but more memory, when img was a uint8 array.
0 commentaires
DGM
le 28 Avr 2022
Modifié(e) : DGM
le 28 Avr 2022
I imagine another obvious interpretation of the question would be "can I store a color image in a 2D array?" with no stipulation that it's a losslessly reversible process. If that's the case, you could always reduce it to an indexed image.
% get an RGB image
rgbpict = imread('peppers.png');
% convert to an indexed image
[indpict cmap] = rgb2ind(rgbpict,256);
% display
imshow(indpict,cmap)
% how many channels does it have? just one.
size(indpict)
Unless the source image is a very simple synthetic image with relatively few colors, the process will irreversibly lose information. You can certainly convert the indexed image back to RGB with ind2rgb(), but don't expect to exactly recover the source image.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
