Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Image Processing.

  1. Nov 5, 2009 #1
    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);
    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


    %out_image = transfer_function(pic2);

  2. jcsd
  3. Nov 12, 2009 #2
    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(:)));
    for a=1:M
    for b=1:N

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook