Please can someone help me out with this code?
显示 更早的评论
This code is giving me error message (FUNCTION keyword use is invalid here, this might cause later message about END).
df=findobj('tag', 'edit3 ');
sdf=get( df,'string');
fg=['c:/users/gabs/documents/matlab/Segmented' sdf];
vv =imread(fg);
if ndims(vv)==3
I=rgb2gray(vv);
else
I=vv;
end
vv=I;
N = normalise(vv,O,l); % normalise to have zero mean, unit std dev
yu=['Originallmage:', sdf];
po=['c:/users/Deji/documents/matlab/Normalized ',sdf];
imwrite(N,po );
%subplot(1 ,2,1), imshow(I,'initialmagnification' ,215), title(yu);
imshow(N),title(strcat(po ));
% This function normalizes the image to desired mean of 0 and variance of 1
function gb = normalise(image,desiremean,desirevar)
if ~(margin == 1 || margin == 3)
error('No of arguments must be 1 or 3');
end
if margin == 1 % Normalisc 0 - 1
ifndims(image) ~= 3; % Assume colour i.mage
else % Normalise to desired mean and variance
if ndims(image) == 3 % colour image?
error('cannot normalise colour image to desired mean and variance');
end
if ~isa(dsafimage,'double')
image = double(image);
end
image = image - mean(image(:));
image = image/std(image(:)); % Zero mean, unit std dev
gb = desiremean + image*sqrt(desirevar);
end
回答(2 个)
Matt Fig
2012-8-16
0 个投票
Where is this code located? If you have it in a script or at the command line, that would explain why you get that error.
Azzi Abdelmalek
2012-8-16
save this function
function gb = normalise(image,desiremean,desirevar)
if ~(margin == 1 || margin == 3)
error('No of arguments must be 1 or 3');
end
if margin == 1 % Normalisc 0 - 1
ifndims(image) ~= 3; % Assume colour i.mage
else % Normalise to desired mean and variance
if ndims(image) == 3 % colour image?
error('cannot normalise colour image to desired mean and variance');
end
if ~isa(dsafimage,'double')
image = double(image);
end
image = image - mean(image(:));
image = image/std(image(:)); % Zero mean, unit std dev
gb = desiremean + image*sqrt(desirevar);
end
then run this part of your code
df=findobj('tag', 'edit3 ');
sdf=get( df,'string');
fg=['c:/users/gabs/documents/matlab/Segmented' sdf];
vv =imread(fg);
if ndims(vv)==3
I=rgb2gray(vv);
else
I=vv;
end
vv=I;
N = normalise(vv,O,l); % normalise to have zero mean, unit std dev
yu=['Originallmage:', sdf];
po=['c:/users/Deji/documents/matlab/Normalized ',sdf];
imwrite(N,po );
%subplot(1 ,2,1), imshow(I,'initialmagnification' ,215), title(yu);
imshow(N),title(strcat(po ));
1 个评论
Walter Roberson
2012-8-16
The function should be saved in the file normalise.m
类别
在 帮助中心 和 File Exchange 中查找有关 Image Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!