3D array of an image to 2D array of the same image

조회 수: 1 (최근 30일)
Ashish Bhatt
Ashish Bhatt 2011년 12월 20일
Hi,
How can I transform a 3D array (of an image) to 1 2D array of the same image without loosing the image, of course, but resulting grayscale image is acceptable. For example,
jpegimage = imread('image001','jpeg');
>> size(jpegimage)
ans =
288 384 3
'jpegimage' is a 3D array. I want this array to convert into a 2D array. I did some experiments with MS paint and saw that converting a JPEG image to a GIF does exactly the same.i.e.:
>> imread('image','gif');
>> size(ans)
ans =
288 384
>>
And the resulting image looks exactly similar (grayscale due to imshow function). But I cannot do this with MS paint because I have huge collection of images. Therefore I try following:
>> imwrite(jpegimage,'Image002','gif');
Warning: Image data contains values that are out of range. Out of range values will be given the nearest valid value.
> In imagesci\private\writegif at 339 In imwrite at 406
But what i get as a result is a 3*1 GIF image.
Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 20일
img2d = rgb2gray(jpegimage);
  댓글 수: 2
Ashish Bhatt
Ashish Bhatt 2011년 12월 20일
Thanks Walter! Is there a way to retain the color? just curious.
Walter Roberson
Walter Roberson 2011년 12월 20일
rgb2ind() can retain the color while producing a 2D array, by using an auxiliary array (a "color map") to store some color information. However, the numbers (indices) for any one pixel of the 2D array will not necessarily be correlated: color index 6 might be black, color index 7 might be red, color index 8 might be green, color index 9 might be hot pink, color index 10 might be a slightly different shade of green... just no inherent ordering to or meaning for the values. As such, there are not many meaningful ways to process the 2D color index array, not even for something as conceptually simple as calculating the mean of the image.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by