Linear contrast stretch to image?
37 views (last 30 days)
Show older comments
Hi, I am very new to image manipulation and MatLab.
I am asked to perform a linear contrast stretching on an image using the defined function histogramlinearstretch. How would I do this? I am not sure what "m" is in this case, and how to apply the function to the image.
Unfortunately I can't upload a .raw file, so the code will show an error, but please ignore that.
infrared = fread( fopen( 'band.raw', 'r'), [1000 1000], '*uint8')';
figure('Renderer', 'painters'),colormap('gray')
imshow(infrared)
function a = histogramlinear(m)
minimum_pixel = double(min(min(m)));
maximum_pixel = double(max(max(m)));
a = uint8(255*(double(m) - minimum_pixel)/(maximum_pixel-minimum_pixel));
end
%Display the image and plot the histogram
colormap('gray'),
0 Comments
Answers (1)
Sarvesh Kale
on 6 Mar 2023
You are trying to perform linear contrast stretch to an image, so basically you are trying to map your intensities [xmin xmax] in image pixels 0 to 255 range which is done by your function histogramlinear, this function will receive the image you are trying to do contrast stretching on an example snippet is shown below
img1 = imread('pout.tif');
minimum_pixel = double(min(min(img1))); % give minimum pixel intensity
maximum_pixel = double(max(max(img1))); % give maximum pixel intensity
img2 = uint8(255*(double(img1) - minimum_pixel)/(maximum_pixel-minimum_pixel));
figure ;
title('Contrast adjustment by linear scaling')
imshow([img1,img2])
You can see that the left image transforms to right image from your code, I hope this helps, please accept the answers if it does
Thank you .
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!