sanjeev
sanjeev

Reputation: 39

Create a Gray level Mask using Matlab and write the same as a gray level image.

I am producing a gray level pattern to be loaded on my SLM (Spatial Light Modulator). The pattern is 1920x1080 pixels. I have 255 gray level values. I tried out this code to create a gray level mask . when I open in Matlab I could see it as gray level, but when I write the image as a bmp file and then it becomes a binary file. How can I resolve this. Following is my code.

clear all
close all
mask=zeros(1080,1920);
% imshow(mask,[])

for k=1:500
for i=1:1080
mask(i,k)=randperm(256,1);
end
end



% mask3=Fit_GrayLevel_To_SLM_Vector(mask);
imshow(mask,[])
imwrite(mask,'mymask4.bmp')

Upvotes: 0

Views: 106

Answers (1)

Bentoy13
Bentoy13

Reputation: 4974

imshow does not make the same assumption as imwrite on the input image dynamic. More precisely, from the doc of imwrite:

If A is a grayscale or RGB color image of data type double or single, then imwrite assumes that the dynamic range is [0,1] and automatically scales the data by 255 before writing it to the file as 8-bit values

So store your data either in a uint8 array, or divide the pixel value by 255 before writing the file.

Upvotes: 2

Related Questions