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 .