basic Image processing problems
3 views (last 30 days)
Show older comments
I am supposed to write function that does this:
gamma(in_image, g) -Return an image in which the intensity of each pixel of in_image is first readjusted to the range [0 1], then raised to the power 1/g, and finally rescaled to [0 255].
my function , which does not work
function [ pic ] = gamma( in_image,g )
i=imread(in_image);
h=i/255 % scales brightness values to be between 0 to 255
h=h^(1/g)% raise to power of 1/g
h=h*255 % scales back to 255
pic=imshow(h); %shows image
and another problem that does not work binarize(image) -Return an image in which all values less than 127 become 0, and all greater than 128 become 255.
function [ pic] = binarize( image )
i=imread(image);
if i<127 i=0
elseif i>128 i=255
else i=i
pic=imshow(i);
I dont see why it won't work; ive been gettin really mad at this stuff,
0 Comments
Answers (3)
Walter Roberson
on 28 Feb 2011
Hint: you are running in to problems with your gamma() function because you are not being careful about your data types. imshow() of an array which of double precision data type expects the data values to be in the range [0,1], but imshow() of an array which is of uint8 data type expects the data values to be in the range 0 to 255.
This problem extends to even when you read the image: you don't know before hand whether you are going to get values in the range [0,1] or in the range 0 to 255 (uint8) or in the range 0 to 65535 (uint16)
0 Comments
Bjorn Gustavsson
on 28 Feb 2011
OK, here's the things I'd change:
h=i/255; %->
h = (i - min(i(:)))/(max(i(:)-min(i(:))));
and further I guess that you should read up on the differences between .*, *; ./, / and .^ and ^. And then change:
h = h^(1/g); %->
h = h.^(1/g);
HTH, Bjeorn
0 Comments
matar maoz
on 28 Feb 2011
I am giving you a solution for your second problem.
you have things you did wrong with your code, but I tried to stick to it as much as possible so you could see what to change
clear clc close all i=imread('cameraman.tif'); figure imshow(i) [numr,numc]=size(i); for rows=1:numr for culls=1:numc
if i(rows,culls)<127 i(rows,culls)=0;
elseif i(rows,culls)>128 i(rows,culls)=255;
%else i=i----------------->>that row is doing nothing end end end
figure imshow(i)
Matar Maoz Afeka college of engineering
0 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!