Matlab Image Processing: Widening Intensity Range using Transfer Function

Click For Summary
SUMMARY

The discussion focuses on using MATLAB for image processing to widen the intensity range of an image with a narrow histogram. The proposed solution involves implementing a linear transfer function that maps the minimum and maximum pixel values to the range [0, 255]. The user encountered difficulties in applying the function to each pixel of the image. A working example was provided, demonstrating the use of nested loops to iterate through pixel values and apply the transformation correctly.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with image processing concepts, specifically intensity histograms
  • Knowledge of pixel manipulation techniques in MATLAB
  • Experience with MATLAB functions such as imread and imagesc
NEXT STEPS
  • Explore MATLAB's rgb2gray function for converting color images to grayscale
  • Learn about histogram equalization techniques in MATLAB
  • Investigate the use of vectorization in MATLAB to optimize pixel processing
  • Study the implementation of custom transfer functions for image enhancement
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in image processing, computer vision, and anyone looking to enhance image quality through intensity manipulation techniques.

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

Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 14 ·
Replies
14
Views
8K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K