MATLAB Answers

Jia Yu
0

how to create a black image?

Asked by Jia Yu
on 8 Dec 2018 at 14:18
Latest activity Commented on by Jia Yu
on 11 Dec 2018 at 12:30
how can i create a black image, not a gray one?

  1 Comment

Jia Yu
on 8 Dec 2018 at 20:20
thanks for reminding!

Sign in to comment.

1 Answer

Answer by Cris LaPierre on 8 Dec 2018 at 19:10
Edited by Cris LaPierre on 8 Dec 2018 at 19:13
 Accepted Answer

Can you use imshow?
If you have to use imagesc, keep in mind that an image has to have values for R, G and B for each pixel. That means you matrix needs to be 256x64x3.
Try using imagesc with this
img=zeros(256,64,3,'uint8');

  3 Comments

Jia Yu
on 8 Dec 2018 at 20:19
thank you so much!
You can also create a gray scale image, rather than an RGB color image if you do
img = zeros(256, 64, 'uint8');
Also note that imagesc() does not require a color image. You can pass it a grayscale image. However it, for some weird reason, pseudocolors it. To turn off the colormap, you can apply a colormap of all grays:
grayImage = imread('cameraman.tif'); % Read in a gray scale image.
imagesc(grayImage); % Display it with a funky colormap
colormap(gray(256)); % Turn the colormap off by making it normal gray.
Jia Yu
on 11 Dec 2018 at 12:30
thanks!

Sign in to comment.