not enough input arguments
8 ビュー (過去 30 日間)
古いコメントを表示
function denoise=normal_shrink(noisy);
noisy= imresize(noisy,[256 256]);
[r c]=size(noisy);
[cc ss]=wavedec2(noisy,1,'sym8');
%approximation coeff - low frequency band
approx = appcoef2(cc,ss,'sym8',1);
% detail coeff in 3 orientation - high frequency bands
dia=detcoef2('d',cc,ss,1);
[hori,vert,dia] = detcoef2('all',cc,ss,1);
Ns=size(noisy,1)*size(noisy,2);
%T= lambda * sigmaY^2 / sigmaX^2;
%lambda = sqrt(log (length of subband at eachlevel)/decomposition level))
%Optimal Threshold value is obtained using the estimatednoise variance, the
%standard deviation of the sub-band of noisy image, and aparameter _.
% noise variance estimate
sigV= median(abs(dia(:)))/0.6745;
sigY21=sum(hori(:).^2)/Ns;
sigY22=sum(vert(:).^2)/Ns;
sigY23=sum(dia(:).^2)/Ns;
% standard deviation calculation
sigx1=sqrt(max(sigY21-sigV^2,0));
sigx2=sqrt(max(sigY22-sigV^2,0));
sigx3=sqrt(max(sigY23-sigV^2,0));
% thresholding parameter
if sigV^2<sigY21
th1=sigV^2/sigx1;
else
end
th1=max(abs(hori(:)));
if sigV^2<sigY22
th2=sigV^2/sigx2;
else
end
th2=max(abs(vert(:)));
if sigV^2<sigY23
th3=sigV^2/sigx3;
else
end
th3=max(abs(dia(:)));
th1=th1*sqrt(log(Ns));
th2=th2*sqrt(log(Ns));
th3=th3*sqrt(log(Ns));
%soft thresholding
hori_t=wthresh(hori,'s',th1);
vert_t=wthresh(vert,'s',th2);
dia_t=wthresh(dia,'s',th3);
approx_t=approx;
rec=[approx_t(:)' hori_t(:)' vert_t(:)' dia_t(:)'];
denoise=waverec2(rec,ss,'sym8');
denoise=wiener2(denoise);
% figure('NAME','normal-shrink'),imshow(denoise,[]);
jn=double(noisy);
jd=jn(:); fd=denoise(:);
snr1=10*log(sum(jd.^2)/(sum((jd-fd).^2)))/log(10)
psnr1=(10*log((max(jd(:)).^2)/(sum((jd-fd).^2)/(size(denoise,1)*size(denoise,2))))/log(10))
function [k, class, img_vect] = kmeans(img,k);
img = double(img);
img = imresize(img, [256,256]);
img_vect = img(:);
centroid = zeros(k,1);
class = zeros(length(img_vect), k);
%initialize centroid
maximum = max(img_vect);
for cent = 1:k
centroid(cent,1)= cent * maximum / k;
end
iter = 0;
while(iter<10)
class(1:length(img_vect),1:k) = 0;
% classifying pixels
for i = 1: length(img_vect)
[val, ind]=min(abs(img_vect(i)-centroid((1:k),1)));
class(i,ind)= img_vect(i);
end
% updating centroid
for cent = 1:k
centroid(cent, 1)=sum(class(:,cent))/length(find(class(:,cent)));
end
iter = iter +1;
end
%figure;imshow(img,[]),title('original');
% for clust = 1:k
% cluster =
reshape(class(1:length(img_vect),clust:clust), [256,256]);
% figure; imshow(cluster,[]),title('cluster');
% end
function img=krischEdge(i);
% Kirsch comapss masks edges detected in 8 directions
i=imresize(i,[256 256]);
% figure, imshow(i,[])
[r c]=size(i);
e=zeros(r+2,c+2);
for m=2:r+1
for n=2:c+1
e(m,n)=i(m-1,n-1);
end
end
% figure, imshow(e,[])
no=zeros(r,c);
nw=zeros(r,c);
w=zeros(r,c);
sw=zeros(r,c);
s=zeros(r,c);
se=zeros(r,c);
ea=zeros(r,c);
ne=zeros(r,c);
for m=2:r+1
for n=2:c+1
no(m-1,n-1)=(e(m-1,n-1)*-3)+(e(m-1,n)*-3)+(e(m1,n+1)*5)+(e(m,n-1)*-3)+(e(m,n)*0)+(e(m,n+1)*5)+(e(m+1,n1)*-3)+(e(m+1,n)*-3)+(e(m+1,n+1)*5);
nw(m-1,n-1)=(e(m-1,n-1)*-3)+(e(m-1,n)*5)+(e(m1,n+1)*5)+(e(m,n-1)*-3)+(e(m,n)*0)+(e(m,n+1)*5)+(e(m+1,n1)*-3)+(e(m+1,n)*-3)+(e(m+1,n+1)*-3);
w(m-1,n-1)=(e(m-1,n-1)*5)+(e(m-1,n)*5)+(e(m1,n+1)*5)+(e(m,n-1)*-3)+(e(m,n)*0)+(e(m,n+1)*-3)+(e(m+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m,n+1)*0)+(e(m+1,n1)*-1)+(e(m+1,n)*-2)+(e(m+1,n+1)*-1)+(e(m-2,n-2)*2)+(e(m2,n-1)*2)+(e(m-2,n)*4)+(e(m-2,n+1)*2)+(e(m2,n+2)*2)+(e(m-1,n-2)*1)+(e(m-1,n+2)*1)+(e(m,n2)*0)+(e(m,n+2)*0)+(e(m+1,n-2)*-1)+(e(m+1,n+2)*-1)+(e(m+2,n-2)*-2)+(e(m+2,n-1)*-2)+(e(m+2,n)*-4)+(e(m+2,n+1)*-2)+(e(m+2,n+2)*-2);gy(m-2,n-2)=(e(m-1,n-1)*-1)+(e(m-1,n)*0)+(e(m1,n+1)*1)+(e(m,n-1)*-2)+(e(m,n)*0)+(e(m,n+1)*2)+(e(m+1,n1)*-1)+(e(m+1,n)*0)+(e(m+1,n+1)*1)+(e(m-2,n-2)*-2)+(e(m2,n-1)*-1)+(e(m-2,n)*0)+(e(m-2,n+1)*1)+(e(m2,n+2)*2)+(e(m-1,n-2)*-2)+(e(m-1,n+2)*2)+(e(m,n-2)*-4)+(e(m,n+2)*4)+(e(m+1,n-2)*-2)+(e(m+1,n+2)*2)+(e(m+2,n2)*-2)+(e(m+2,n-1)*-1)+(e(m+2,n)*0)+(e(m+2,n+1)*1)+(e(m+2,n+2)*2);
end
end
img=double((gx.^2 + gy.^2).^(0.5));
function B=imbilatfilt(ns);
% preserve edges. The intensity value at each pixel in an
image is replaced by a
% weighted average of intensity values from nearby pixels
% Start of bilateral filter
% gaussian distance weights
w = 5;
sigma = [3 0.1];
[X,Y] = meshgrid(-w:w,-w:w);
G = exp(-(X.^2+Y.^2)/(2*sigma(1)^2));
dim = size(ns);
B = zeros(dim);
for ii = 1:dim(1)
for jj = 1:dim(2)
iMin = max(ii-w,1);
iMax = min(ii+w,dim(1));
jMin = max(jj-w,1);
jMax = min(jj+w,dim(2));
I = ns(iMin:iMax,jMin:jMax);
H = exp(-(I-ns(ii,jj)).^2/(2*sigma(2)^2));
F = H.*G((iMin:iMax)-ii+w+1,(jMin:jMax)-jj+w+1);
B(ii,jj) = sum(F(:).*I(:))/sum(F(:));
end
end
1 件のコメント
Walter Roberson
2020 年 10 月 26 日
Which line is giving the error?
When you invoke the code, what size() is the input data are you passing to it?
回答 (1 件)
Srivardhan Gadila
2020 年 10 月 30 日
I have tested your code for the following input:
noisy = uint8(randi([0 255],100,100));
and I'm not getting any errors. Also it seems that there are some syntax errors like not terminating the local function within a function/script file and etc (I have attached the updated code I have tested). Refer to function, Function Basics & Declare Function.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Least Squares についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!