下面是网上找的用matlab实现的磨皮算法代码,要求将其写到GUI界面,求其中GUI界面的function pushbotton后面应该怎么修改?
img=imread('xxx.jpg');
noisyImg=imread('xxx.jpg');
r=10;
level=5;
sigma=10+level^2;
dnImg=denoiseBasedLocalStat(noisyImg,r,sigma);
figure,imshow(dnImg);
function dnImg = denoiseBasedLocalStat(img,r,sigma)% 图像滤波去噪
if size(img,3)==1%灰度图,则直接进行灰度图像滤波去噪
img=double(img);
dnImg=denoiseBasedLocalStat_gray(img,r,sigma);
dnImg=uint8(dnImg);
end
if size(img,3)==3%彩色图,则提取出表示亮度的ycbcr矩阵,进行灰度图像滤波去噪
ycc=rgb2ycbcr(img);
y=ycc(:,:,1);
dnY=denoiseBasedLocalStat_gray(double(y),r,sigma);
ycc(:,:,1)=uint8(dnY);
dnImg=ycbcr2rgb(ycc);%去噪后重新转回颜色矩阵
end
end
function dnImg=denoiseBasedLocalStat_gray(img,r,sigma)%灰度图像滤波去噪
dnImg=zeros(size(img));
img=double(img);
paddedImg=padarray(img,[r,r],'symmetric','both');
[Yim,YYim]=intergalMap(paddedImg);
for i=r+1:size(paddedImg,1)-r
for j=r+1:size(paddedImg,2)-r
rectSum=Yim(i+r+1,j+r+1)+Yim(i-r,j-r)-Yim(i-r,j+r+1)-Yim(i+r+1,j-r);
rectSquareSum=YYim(i+r+1,j+r+1)+YYim(i-r,j-r)-YYim(i-r,j+r+1)-YYim(i+r+1,j-r);
num=(2*r+1)^2;
avg=rectSum/num;
var=rectSquareSum/num-avg^2;
k=var/(var+sigma^2);
dnImg(i-r,j-r)=(1-k)*avg+k*img(i-r,j-r);
end
end
end
function [Yim,YYim]=intergalMap(img)
% 生成积分图
paddedImg=padarray(img,[1 1],0,'pre');%图像矩阵的第一列左边与第一行上面均补上0
Yim=zeros(size(paddedImg));
YYim=Yim;
for i=2:size(paddedImg,1)
for j=2:size(paddedImg,2)
Yim(i,j)=Yim(i,j-1)+Yim(i-1,j)-Yim(i-1,j-1)+paddedImg(i,j);
YYim(i,j)=YYim(i,j-1)+YYim(i-1,j)-YYim(i-1,j-1)+paddedImg(i,j)^2;
end
end
end
GUI的实现
axis off
[filename pathname] =uigetfile({'.jpg';'.bmp';'.'},'打开图片');
str=[pathname filename];
im=imread(str);
axes(handles.axes1);
然后后面不会写了
求帮助!