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

  • Context: MATLAB 
  • Thread starter Thread starter Saikiran
  • Start date Start date
  • Tags Tags
    Code Image
Click For Summary
SUMMARY

The discussion centers around troubleshooting image enhancement code in MATLAB, specifically using functions like imread, rgb2gray, and ginput. Users encountered errors related to pixel manipulation and matrix indexing while attempting to create selected, maximum, and minimum neighboring pixel matrices. The code also includes a manual thresholding technique using mean2 for binary image conversion. Participants emphasized the importance of sharing error messages for effective debugging.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of image processing concepts, particularly pixel manipulation
  • Knowledge of matrix indexing in MATLAB
  • Experience with image thresholding techniques
NEXT STEPS
  • Explore MATLAB's ginput function for interactive data collection
  • Learn about MATLAB image processing functions such as im2bw and graythresh
  • Investigate error handling in MATLAB to improve debugging practices
  • Study advanced image enhancement techniques, including morphological operations
USEFUL FOR

Image processing enthusiasts, MATLAB developers, and researchers looking to enhance image quality and troubleshoot related coding issues.

Saikiran
Messages
1
Reaction score
0
TL;DR
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
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

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K