Reputation:
How can I decrease a picture's brightness levels in MATLAB? For example from 256 (in 8-bit pictures) to 10?
Upvotes: 2
Views: 1414
Reputation: 15996
I would recommend the following code, which may accomplish what you're looking for more directly:
srcBitDepth = 8;
dstBitDepth = 2;
img = imread('cameraman.tif');
subplot(1,2,1); imshow(img,[]);
img = bitshift(img, dstBitDepth-srcBitDepth);
subplot(1,2,2); imshow(img,[]);
Here's the result:
Notice the bit reduction from an original 8-bit image to a 2-bit image.
Upvotes: 3
Reputation: 74940
To convert an image from X
graylevels into an image with Y
graylevels, you can write
modifiedImage = round( double(rawImage)/X * Y);
Then you can convert modifiedImage
to the integer format of your choice, e.g. uint8
modifiedImage = uint8(modifiedImage);
Upvotes: 2