Hi, I am applying an algorithm on an Image which is so big 7001x7851. I am using many loops according to the algorithm and it takes much time to get the result. I am trying to use block processing but do not know how to get the 'fun'. here is my code
Show older comments
Tb1= imread([datapath71,datafile71]);
Fb1= imread([datapath51,datafile51]);
[r,c] = size(Tb1);
[m,n] = size(Fb1);
if r ~= m || c ~= n
Fb1 = imresize(Fb1, [r,c]);
end
figure;imshow(Fb1);title('Actual');
figure(2);imshow(Tb1);title('Target');
Tb1=im2double(Tb1);
Fb1=im2double(Fb1);
[r,c]=size(Tb1);
no = nnz(~Tb1);
fprintf('Total no of zeros = %g.\n',no);
no1=0; % no of filled gaps
% win_s='Enter the window size';
W = 9;
Mt= zeros(size(Tb1));
Mf= zeros(size(Fb1));
comv=zeros(size(Tb1));
for i=W:r-(W-1)
for j=W:c-(W-1)
if Tb1(i,j)==0
com=0;St=0;Sf=0;
for k1=i-(W-1):i+(W-1)
for k2=j-(W-1):j+(W-1)
if (Tb1(k1,k2)>0 && Fb1(k1,k2)>0)
St=St+Tb1(k1,k2);
Sf=Sf+Fb1(k1,k2);
com=com+1;
end;
end;
end;
Mt(i,j)=St/com;
Mf(i,j)=Sf/com;
comv(i,j)=com;
end;
end;
end;
New_dn= zeros(size(Tb1));
for i=W:r-(W-1)
for j=W:c-(W-1)
if Tb1(i,j)==0
SDt=0;SDf=0;
for k1=i-(W-1):i+(W-1)
for k2=j-(W-1):j+(W-1)
if (Tb1(k1,k2)>0 && Fb1(k1,k2)>0)
SDt=SDt+(Tb1(k1,k2)-Mt(i,j))^2;
SDf=SDf+(Fb1(k1,k2)-Mf(i,j))^2;
end;
end;
end;
SD_t=SDt/(comv(i,j)-1);
SD_f=SDf/(comv(i,j)-1);
G=SD_t/SD_f;
if (G>3||G<0.3)
G=1;
end;
Bi=Mt(i,j)-Mf(i,j)*G;
ND=Fb1(i,j)*G+Bi;
New_dn(i,j)=ND;
no1=no1+1;
else
New_dn(i,j)=Tb1(i,j);
end;
end;
end;
figure(3);imshow(New_dn);
imwrite(New_dn,'LLHM_b1_4.tif');
fprintf('Total no of filled gaps in Band1= %g.\n',no1);
1 Comment
Walter Roberson
on 18 Sep 2015
What is the code intended to do ?
Answers (1)
Image Analyst
on 18 Sep 2015
0 votes
I don't know what this does but it's not processing in blocks. It's scanning a window a pixel at a time. With only a short glance, it looks like the whole quadruple for loop could be replaced by 3 or 4 lines of code, one to make a binary image of Tb1 and Fb1 are > 0, then another to set Tb1 and Fb1 equal to zero where the binary image is false, then a call to conv2().
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!