필터 지우기
필터 지우기

White 256x256 image gives me 256x256x3

조회 수: 15 (최근 30일)
Osama Hussein
Osama Hussein 2016년 11월 7일
댓글: Walter Roberson 2016년 11월 8일
I need a white 256x256 pixels image to use it in an assignment. I tried to make it using Paint and downloaded white images from the internet, but for some reason when I read the image, it stored in a 256x256x3 variable (color image format). I tried different extensions (jpg, png).
What is the reason? I attached the images I used and here is the code to read the image.
img = double(imread('white.jpg'));
[l,w] = size(img);
figure
imshow(uint8(img)) % display the test image
title('Original image')

채택된 답변

Image Analyst
Image Analyst 2016년 11월 7일
Try this:
whiteImage = 255 * ones(256, 256, 'uint8');
imwrite(whiteImage, 'White Image.png'); % Save to disk.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 11월 8일
Paint is writing as RGB.
Walter Roberson
Walter Roberson 2016년 11월 8일
Paint has no provision for saving as grayscale, only as color and as bitmap (black and white, no gray levels.)

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 7일
jpg images are almost always RGB images, even if they appear grayscale. It is possible to have a grayscale jpg image, but the program would have to support creating it.
You can use rgb2gray() to convert to the equivalent grayscale image.
Caution: you have
[l,w] = size(img);
which is going to give you confusing results for RGB images. You should be using
[l, w, chan] = size(img);
  댓글 수: 2
Osama Hussein
Osama Hussein 2016년 11월 7일
Thank you for your prompt reply. When I used "img = rgb2gray(image);" the variable for the image "img" will be all ones, but I need a greyscale image with pixels between 0 and 256 as previous. Regarding the format of the image, I tried also to use png, but it gives me same result.
Walter Roberson
Walter Roberson 2016년 11월 7일
편집: Walter Roberson 2016년 11월 7일
GrayImage = img(:,:,1);
This will not work for general RGB images but it will work for images that are completely tones of gray stored as RGB images.

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

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by