basic Image processing problems
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Walter Roberson
2011-2-28
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 个评论
Bjorn Gustavsson
2011-2-28
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 个评论
matar maoz
2011-2-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!