How can I decrease a picture's brightness levels in MATLAB?
How can I decrease a picture's brightness levels in MATLAB? For example from 256 (in 8-bit pictu开发者_StackOverflow社区res) to 10?
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.
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);
精彩评论