MATLAB Matlab Image Processing: Widening Intensity Range using Transfer Function

AI Thread Summary
The discussion revolves around transforming an image's pixel intensity values using a linear transfer function in MATLAB. The goal is to widen the intensity range of an image with a narrow histogram by mapping the minimum intensity (I_min) to 0 and the maximum intensity (I_max) to 255. The user is struggling with iterating over each pixel to apply this transformation. Key points include the need to read the image, convert it to grayscale, and calculate I_min and I_max. The proposed solution involves using nested loops to iterate through each pixel, applying the formula to scale the pixel values accordingly. A suggestion was made to avoid using "image" as a variable name since it conflicts with MATLAB's built-in function. The provided code snippets illustrate the process, with one correcting the original approach to ensure proper pixel value transformation and display.
foobag
Messages
75
Reaction score
0
I have to take an image with a narrow intensity histogram and widen its intensity range using a simple transfer function that scales the dominant histogram intensity range [I_min, I_max] to the range [0, 255].

They tell me to tuse a linear function that maps I_min to 0 and I_max to 255 and all intensites I within that range to 255*(I-I_min)/(I_max - I_min).

The problem I am having is how to make it so that the function reads every individual pixel of the image and transforms it to a new pixel value. I am stuck at this part.

Please help since it is my first time using matlab.

Here is my code so far:

function [ output_args ] = imagehisto(image)
%Function that maps pixel values using a transfer function from 0 to 255 if
%it is out of ranage.
% Input of an image, reading each pixel and transferring it to a new
% pixel value.

pic = imread(image);
colormap(gray);
pic2 = rgb2gray(pic);

I_max = double(max(pic2(:)));
I_min = double(min(pic2(:)));


x = (0:1:255)
x = pic2
y(I_min+1 : I_max+1) = (255*(x(I_min+1 : I_max+1) - I_min)/(I_max - I_min))
y(1 :I_min) = 0
y(I_max+2 : 256) = 255

imagesc(pic3);

%plot(x,y);
%out_image = transfer_function(pic2);

end
 
Physics news on Phys.org
First I will admitt it has been a while since I have done image analysis with Matlab but what I think you are asking for is something like this. I'm not familiar with the double command so I'll just assume it is used correctly. Oh and don't use image as an imput and image is a command in matlab.

function [ output_args ] = imagehisto(pic)
I_max = double(max(pic(:)));
I_min = double(min(pic(:)));
[M,N]=size(pic);
for a=1:M
for b=1:N
pic_new(a,b)=255*(pic(a,b)-I_min)/(I_max-I_min);
end
end
imagesc(pic_new)

I used my own dummy data and I got it so change to the range of 0 to 255, so this should work for you.
 

Similar threads

Back
Top