Unable to crack this image enhancement code -- Matlab is throwing errors

  • #1
Saikiran
1
0
TL;DR Summary
Hi everyone !
The code which I mentioned is the code of image enhancement which I am trying to work on. But, it is throwing errors regarding image size mismatch while adding images and also throwing some indentation errors. Any help regarding this would be greatly apprexiated.
Matlab:
img= imread('Image.bmp');
img= rgb2gray(img);
imshow(img);
pt = ginput(4); % the function ginput is used to get the
input from mouse
x1 = pt(1,1);
y1 = pt(1,2);
x2 = pt(2,1);
y2 = pt(2,2);
x = [x1 x2];
y = [y1 y2];
line(x,y);
x3 = pt(3,1);
y3 = pt(3,2);
x4 = pt(4,1);
y4 = pt(4,2);
x = [x2 x3];
y = [y2 y3];
line(x,y);
x = [x3 x4];
y = [y3 y4];
line(x,y);
x = [x4 x1];
y = [y4 y1];
line(x,y);
sidx=1; % selected original image
sidy=1;
uidx =1; % U image i.e. max neighbouring pixel
uidy =1;
vidx =1; % V image i.e. min neighbouring pixel
vidy =1;
 for idx = bx1:bx3
 for idy = by1:by3
 
 % Selected image matrix is created for selected area pixel
by pixel
 S(sidx,sidy) = img(idx,idy);
 sidy = sidy+1;
 
 % Max. Neighbouring Pixel image matrix is created for
selected area pixel by pixel
 
U(uidx,uidy) = img(idx,idy); %
Centre
 %Checking for max. neighbouring pixel
 if(img(idx-1,idy-1) > img(idx,idy)) % 1
 U(uidx,uidy) = img(idx-1,idy-1);
 end
 if(img(idx-1,idy) > img(idx,idy)) % 2
 U(uidx,uidy) = img(idx-1,idy);
 end
 if(img(idx-1,idy+1) > img(idx,idy)) % 3
 U(uidx,uidy) = img(idx-1,idy+1);
 end
 if(img(idx,idy+1) > img(idx,idy)) % 4
 U(uidx,uidy) = img(idx,idy+1);
 end
 if(img(idx+1,idy+1) > img(idx,idy)) % 5
 U(uidx,uidy) = img(idx+1,idy+1);
end
 if(img(idx+1,idy) > img(idx,idy)) % 6
 U(uidx,uidy) = img(idx+1,idy);
end
 if(img(idx+1,idy-1) > img(idx,idy)) % 7
 U(uidx,uidy) = img(idx+1,idy-1);
 end
 end
uidy = uidy+1;
 
 % Min. Neighbouring Pixel image matrix is created for
selected area pixel by pixel
 V(vidx,vidy) = img(idx,idy); %
Centre
 %Checking for min. neighbouring pixel
 if(img(idx-1,idy-1) < img(idx,idy)) % 1
 V(vidx,vidy) = img(idx-1,idy-1);
 end
 if(img(idx-1,idy) < img(idx,idy)) % 2
 V(vidx,vidy) = img(idx-1,idy);
 end
 if(img(idx-1,idy+1) < img(idx,idy)) % 3
 V(vidx,vidy) = img(idx-1,idy+1);
 end
 if(img(idx,idy+1) < img(idx,idy)) % 4
 V(vidx,vidy) = img(idx,idy+1);
 end
 if(img(idx+1,idy+1) < img(idx,idy)) % 5
 V(vidx,vidy) = img(idx+1,idy+1);
 end
 if(img(idx+1,idy) < img(idx,idy)) % 6
 V(vidx,vidy) = img(idx+1,idy);
 end
 if(img(idx+1,idy-1) < img(idx,idy)) % 7
 V(vidx,vidy) = img(idx+1,idy-1);
 end
 vidy = vidy+1;
 end
 sidx = sidx+1;
 sidy = 1;
 uidx = uidx+1;
 uidy = 1;
end
%Thresholding
% level= graythresh(C);
% B= im2bw(C,level); % between zero and one
B=C;
%mL=200; %Threholding applied manually to
image matrix B
mL=mean2(C);
B(B>mL)=255;
B(B<mL)=0;
B2= B + S; % Adding Selected image and
Thresholding Image
subplot(2,3,1);
imshow(S); %selected
subplot(2,3,2);
 
imshow(U); %max
subplot(2,3,3);
imshow(V); %min
subplot(2,3,4);
imshow(C); %Diff
subplot(2,3,5);
imshow(B); %Thresholding done
subplot(2,3,6);
imshow(B2);
pause;
close;
opticalga; % CALL for next program to calculate Ga
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Please copy-paste the errors too, we can't help unless we see the errors and in which line they are occurring. MATLAB isn't concerned about indentation, unlike Python.
 

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • General Discussion
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
10K
  • Calculus and Beyond Homework Help
Replies
12
Views
2K
Back
Top