开发者

How can I decrease a picture's brightness levels in MATLAB?

开发者 https://www.devze.com 2023-03-19 20:08 出处:网络
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\

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:

How can I decrease a picture's brightness levels in MATLAB?

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消