How to adjust the intensity of grayscale image?
56 views (last 30 days)
Show older comments
I create a 200x200 image then convert it to grayscale, how can i adjust its intensity between 0-255?
0 Comments
Answers (3)
Image Analyst
on 1 Jan 2022
There are lots of ways.
grayImage = imadjust(grayImage);
grayImage = rescale(grayImage, 0, 255);
grayImage = 255 * mat2gray(grayImage);
2 Comments
Image Analyst
on 1 Jan 2022
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
on 1 Jan 2022
yes,sir,may be use
im = im2uint8(mat2gray(im));
2 Comments
yanqi liu
on 1 Jan 2022
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)
See Also
Categories
Find more on Explore and Edit Images with Image Viewer App in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!