Can an RGB image be stored as 2D matrix without converting to greyscale image?
8 次查看(过去 30 天)
显示 更早的评论
Can an RGB image be stored as 2D matrix without converting to greyscale image in matlab?
0 个评论
回答(2 个)
Jan
2015-6-29
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 个评论
DGM
2022-4-28
编辑:DGM
2022-4-28
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!