White 256x256 image gives me 256x256x3
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Osama Hussein
le 7 Nov 2016
Commenté : Walter Roberson
le 8 Nov 2016
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157763/image.jpeg)
img = double(imread('white.jpg'));
[l,w] = size(img);
figure
imshow(uint8(img)) % display the test image
title('Original image')
0 commentaires
Réponse acceptée
Image Analyst
le 7 Nov 2016
Try this:
whiteImage = 255 * ones(256, 256, 'uint8');
imwrite(whiteImage, 'White Image.png'); % Save to disk.
3 commentaires
Walter Roberson
le 8 Nov 2016
Paint has no provision for saving as grayscale, only as color and as bitmap (black and white, no gray levels.)
Plus de réponses (1)
Walter Roberson
le 7 Nov 2016
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 commentaires
Walter Roberson
le 7 Nov 2016
Modifié(e) : Walter Roberson
le 7 Nov 2016
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.
Voir également
Catégories
En savoir plus sur Modify Image Colors dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!