Various problems with Matlab's appdesigner.

1 vue (au cours des 30 derniers jours)
Evelyn LeBeau
Evelyn LeBeau le 27 Avr 2023
Hello, I allow myself to post here for the first time since I encounter problems with "Matlab's AppDesigner". First of all, my primary language is english, so my english could be a lit cluncky . I've never used "Matlab's AppDesigner" before, the answers for my questions could be trivial (I hope so). We've been asked to develop an app wich can do some image processing such as converting an image to HSV, to Gray, to add noise to the picture and to apply filters.As sugested by the title, I got various problems, three to be precise :
1-Display RGB/HSV of an imported image:
We've been asked to create a button which can let the user choose the picture he wants. I used this code ( from there ):
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.jpg');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
app.I = imread(fullFileName);
%%%setappdata(app, 'filename', fullFileName);
imshow(app.I,'Parent',app.UIAxes);
The code is working perfectly except that Matlab doesn't seem to consider variables created inside the buttons to be global. I fugured out that i could use the image stored if I do this :
properties (Access = public)
I % Description
end
This worked again but, i'm not able to correctly display the RGB & HSV channels , I get this kind of result :
I used this code here :
app.I;
app.I = double (app.I)/255;
I_red = app.I(:,:,1);
I_green = app.I(:,:,2);
I_blue = app.I(:,:,3);
[h,w,d]= size (app.I);
I_red2 = zeros (h,w,d);
I_green2 = zeros (h,w,d);
I_blue2 = zeros (h,w,d);
I_red2 (:,:,1) = I_red;
I_green2 (:,:,2) = I_green;
I_blue2 (:,:,3) = I_blue;
imshow (I_red2,'Parent',app.UIAxes2_4)
imshow (I_green2,'Parent',app.UIAxes2_5)
imshow (I_blue2,'Parent',app.UIAxes2_6)
Seems like the image is "lost" somehow. Strangely enough, if I use a picture already storred in a imread, it does provide the correct display :
Here, I used the same logic except that I used an imread (Meaning that the problem comes indeed from the importation process):
I = imread('Sky.jpeg');
I = double (I)/255;
I_red = I(:,:,1);
I_green = I(:,:,2);
I_blue = I(:,:,3);
[h,w,d]= size (I);
I_red2 = zeros (h,w,d);
I_green2 = zeros (h,w,d);
I_blue2 = zeros (h,w,d);
I_red2 (:,:,1) = I_red;
I_green2 (:,:,2) = I_green;
I_blue2 (:,:,3) = I_blue;
imshow (I_red2,'Parent',app.UIAxes_10)
imshow (I_green2,'Parent',app.UIAxes_11)
imshow (I_blue2,'Parent',app.UIAxes_12)
I've been trying for so many weeks to understand where does the problem come from without finding a solution. In both cases, the code is the same.
2-Midfilter on RGB & HSV Picture:
This one is particular. I don't know if it's correct but I do think that you may refer to this kind of filter as "Median Filter". For some raison, I am not able to get these code to work (and it is not caused by the fact that the picture is imported by the user):
app.I;
IB = imnoise (app.I,'salt & pepper',0.05);
I_Filter = medfilt2(IB,[3 3]);
imshow(I_Filter,'Parent',app.UIAxes);
I just keep getting this error :
Error using medfilt2
Expected input number 1, A, to be two-dimensional.
Error in medfilt2>parse_inputs (line 107)
validateattributes(a, ...
Error in medfilt2 (line 49)
[a, mn, padopt] = parse_inputs(args{:});
Is there a way to change the "[3,3]" so that it could change depending on the image size if it is the problem ?
3-Low-pass filter and High-pass filter do not always work:
This one is a little hard to explain to explain since I'm not I'm not wrong about these filters name, I'm going to show you what I am talking using pictures from wikipedia :
High-pass filter
Low-pass filter
My problem does come from my codes :
h = -ones(3,3);
h(2,2) = 9;
app.I = rgb2gray(app.I);
app.I = double(app.I)/255.0;
F = filter2(h,app.I);
imshow(F,'Parent',app.UIAxes)
I use this codes to apply high pass filter, sometimes it does work but sometimes all I get a blank white square. The same thing happens for me with the Low pass filter (I have three Low pass filters in my app):
%First one
app.I;
IG = rgb2gray (app.I);
app.I=double(app.I)/255.0;
h1 = ones(3,3)/9;
F1 = filter2(h1,IG)
imshow(F1,'Parent',app.UIAxes)
%Second one
app.I;
IG = rgb2gray (app.I);
app.I=double(app.I)/255.0;
h3 = ones(7,7)/49;
F3 = filter2(h3,IG)
imshow(F3,'Parent',app.UIAxes)
%Third one
app.I;
IG = rgb2gray (app.I);
app.I=double(app.I)/255.0;
h2 = ones (7,7)/25;
F2 = filter2(h2,IG)
imshow(F2,'Parent',app.UIAxes)
That's all, my post migth be very long and I am sorry about it, I just wanted to be clear. Thanks in advance.

Réponses (1)

Evelyn LeBeau
Evelyn LeBeau le 28 Avr 2023
I found a solution for my second question, just needed to use medfilter3 instead of medfilter2.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by