How to adjust the intensity of grayscale image?
56 次查看(过去 30 天)
显示 更早的评论
I create a 200x200 image then convert it to grayscale, how can i adjust its intensity between 0-255?
0 个评论
回答(3 个)
Image Analyst
2022-1-1
There are lots of ways.
grayImage = imadjust(grayImage);
grayImage = rescale(grayImage, 0, 255);
grayImage = 255 * mat2gray(grayImage);
2 个评论
Image Analyst
2022-1-1
They are not totally black. Did you look at them in the workspace? They will have non-zero values. Try displaying with [] as the second argument to imshow:
imshow(grayImage, []);
Of course with the sample code you gave, where you defined Image as a totally black image, you will get a totally black image even after it's contrast stretched. You have to use an image that actually has some structure to it and is not all black.
Don't use Image as the name of a variable since there is a built-in function image().
grayImage = imread('pout.tif');
subplot(1, 2, 1);
imshow(grayImage);
if ndims(grayImage) == 3
grayImage = rgb2gray(grayImage);
end
grayImage = imadjust(grayImage);
subplot(1, 2, 2);
imshow(grayImage, []);
yanqi liu
2022-1-1
yes,sir,may be use
im = im2uint8(mat2gray(im));
2 个评论
yanqi liu
2022-1-1
yes,sir,may be use
%create a 200x200 image then convert it to grayscale,
%how can i adjust its intensity between 0-255?
% create a 200x200 image
im = rand(200,200,3);
% then convert it to grayscale
im = rgb2gray(im);
im(1:10,1:10)
% adjust its intensity between 0-255
im = im2uint8(mat2gray(im));
im(1:10,1:10)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!