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.
 

What does the error message in Matlab typically indicate when it mentions "Unable to crack this image enhancement code"?

The error message "Unable to crack this image enhancement code" typically isn't a standard Matlab error and might be a custom error message in your script. Generally, Matlab errors provide specifics about what went wrong, such as syntax errors, incompatible types, or out-of-bounds indices. Check your script for any custom error messages or exceptions that might have been defined by the user or previous developers.

How can I debug Matlab errors effectively when working on image enhancement?

To debug Matlab errors effectively, start by examining the full error message, which usually includes the line number where the error occurred. Use Matlab's debugging tools like breakpoints to pause execution and inspect variables at various points. Ensure all image data is correctly formatted and that no operations exceed array bounds. Checking the compatibility of image formats and types before operations can also prevent many common issues.

What are common mistakes to avoid in Matlab when coding for image enhancement?

Common mistakes in Matlab for image enhancement include not preallocating arrays which can lead to performance issues, using incorrect array indices, misunderstanding image data types and formats, and applying enhancement algorithms without adjusting for the specific characteristics of the image data. Always verify that the operations used are suitable for the image type, such as floating-point versus integer or grayscale versus RGB.

Can Matlab handle all types of image formats for enhancement purposes?

Matlab can handle a wide range of image formats including, but not limited to, JPEG, PNG, TIFF, and BMP. However, some formats, especially proprietary or less common ones, might require additional tools or toolboxes for proper reading and writing. Always check that you have the necessary functions and toolboxes to handle specific image formats, particularly when dealing with specialized medical or scientific imaging formats.

What resources are available for learning more about image enhancement techniques in Matlab?

Matlab provides extensive documentation and tutorials on image processing and enhancement, available through MathWorks’ official website. Additionally, there are many books, online courses, and community forums dedicated to Matlab image processing. Toolboxes like Image Processing Toolbox offer built-in functions and examples that are particularly useful for learning advanced image enhancement techniques.

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