MATLAB app designer error which is related to a function
1 view (last 30 days)
Show older comments
I got an error while I was writing code.
Honestly, I am matlab beginner, so I am not sure how I can fix the code.
I really appreciate your help.
Error message
Error using wavefast
x must be a real, numeristic 2-D or 3-D matrix.
Error in function 2 (line 9)
[C,S] = wavefast(image, 1, 'haar')
my code for app
% Value changed function: SelectafunctionDropDown
function SelectafunctionDropDownValueChanged(app, event)
global image1;
switch app.SelectafunctionDropDown.Value
case'Function1'
[~, IndexImg] = Function1(image1, app.Threshold1EditField.Value);
imagesc(IndexImg,'Parent',app.UIAxes2);
[~, IndexImg] = Function1(image1, app.Threshold2EditField.Value);
imagesc(IndexImg,'Parent',app.UIAxes3);
case 'Function2'
% imshow(image1,'Parent',app.UIAxes);
[~, IndexImg] = Function2(image1, app.Threshold1EditField.Value); %here where I got the error
imagesc(IndexImg,'Parent',app.UIAxes2);
[~, IndexImg] = Function2(image1, app.Threshold2EditField.Value);
imagesc(IndexImg,'Parent',app.UIAxes3);
end
end
Function 2 code
function [EdgeImg, IndexImg] = Function2(InputImg, Threshold)
image = InputImg;
if size(image, 3) == 3
image = rgb2gray(image);
end
[C,S] = wavefast(image,1,'haar'); %Here is the line that the app designer mentioned
% figure;wavedisplay(C,S);
[NC,~] = wavecut('a',C,S);
[NC,~] = wavecut('v',NC,S,1);
[NC,~] = wavecut('d',NC,S,1);
R1 = waveback(NC,S,'haar',1);
[NC,~] = wavecut('a',C,S);
[NC,~] = wavecut('h',NC,S,1);
[NC,~] = wavecut('d',NC,S,1);
R2 = waveback(NC,S,'haar',1);
[NC,~] = wavecut('a',C,S);
[NC,~] = wavecut('h',NC,S,1);
[NC,~] = wavecut('v',NC,S,1);
R3 = waveback(NC,S,'haar',1);
% Initial Edgelmg and Indexlmh??
EdgeImg = zeros(size(image,1),size(image, 2));
IndexImg = zeros(size(image,1),size(image, 2));
for k = 1:size(image,1)
for m = 1:size(image,2)
%find max value of R1 and R2 at each pixel
[R, jip] = max([R1(k,m), R2(k,m), R3(k,m)]);
if R >= Threshold
EdgeImg(k,m) = R;
IndexImg(k,m) = jip;
else
EdgeImg(k,m) = 0;
IndexImg(k,m) = 4;
end
end
end
end
If you need more code info, please let me know.
Thank you for your help in advance
1 Comment
Walter Roberson
on 28 Apr 2023
global image1;
We do not know what is in that global variable. Might be empty. Might be the name of an image file.
Why are you using global variables with app designer? Do you need to share the values between multiple App Designer interfaces? If not then make the variable a property of app
Answers (1)
Raghav
on 5 May 2023
Hi,
Based on the question, it can be understand that you are facing issues with using wavefast function in your code.
The error message suggests that the input matrix to the wavefast function in Function2 should be a real, numeric 2-D or 3-D matrix.
One possible reason for this error is that the input image matrix (InputImg) in Function2 is not a valid input for the wavefast function.
You could try checking the input image matrix and make sure it is a real, numeric 2-D or 3-D matrix. Also, you may want to make sure that the image is loaded properly and it is in the expected format.
If the input image is not the issue, you could try modifying the wavefast function by specifying the input arguments in the correct format. For example, if the image is a grayscale image, you could specify the third argument of wavefast function as 'haar' to specify the wavelet type.
Here is an updated version of Function2 with some modifications and error checking:
function [EdgeImg, IndexImg] = Function2(InputImg, Threshold)
% Check if the input image is valid
if ~(isreal(InputImg) && isnumeric(InputImg) && (ndims(InputImg) == 2 || ndims(InputImg) == 3))
error('Input image must be a real, numeric 2-D or 3-D matrix.');
end
% Convert the image to grayscale if it is a color image
if size(InputImg, 3) == 3
InputImg = rgb2gray(InputImg);
end
% Call wavefast with the correct input arguments
if ndims(InputImg) == 2
[C,S] = wavefast(InputImg, 1, 'haar');
else
[C,S] = wavefast(InputImg(:,:,1), 1, 'haar');
end
% Rest of the code
Hope it helps,
Raghav Bansal
0 Comments
See Also
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!