How can i read images for filtering using if else condition in GUI?

2 vues (au cours des 30 derniers jours)
PinYu Chen
PinYu Chen le 23 Mai 2022
Modifié(e) : DGM le 24 Mai 2022
case '[-1 -1 0;-1 0 1;0 1 1]'
Image_gray = rgb2gray(app.Image);
c = [-1 -1 0;-1 0 1;0 1 1];
XG1 = imfilter(Image_gray,c,'parent',app.UIAxes_3);
imshow(XG1,'parent',app.UIAxes_3)
title('[-1 -1 0;-1 0 1;0 1 1]','parent',app.UIAxes_3)
end
  2 commentaires
Stephen23
Stephen23 le 23 Mai 2022
What do you expect the 'parent' option to achieve? I do not see it mentioned in the IMFILTER documentation.
PinYu Chen
PinYu Chen le 23 Mai 2022
Place the image on app.UIAxes_3.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 23 Mai 2022
Modifié(e) : Jan le 23 Mai 2022
imfilter operates on the pixel values of an image. See: imfilter . There is no "parent" property, so simply omit this:
% XG1 = imfilter(Image_gray,c,'parent',app.UIAxes_3);
XG1 = imfilter(Image_gray,c);
imshow has a "parent" property, but this is a completely different command.
  2 commentaires
PinYu Chen
PinYu Chen le 24 Mai 2022
Thanks, but I changed the code and it still doesn't work.
DGM
DGM le 24 Mai 2022
Modifié(e) : DGM le 24 Mai 2022
Do you have Image Processing Toolbox?
If you don't, you can get partway there with conv2(), but you'll have to deal with edge padding and cropping. In this example, I'm replicating the "replicate" padding option, which is not the default behavior of imfilter(). The default can be accomplished by padding with zeros.
inpict = imread('cameraman.tif'); % the image
fk = ones(5)/25; % the filter
% pad the image
fw = size(fk);
outpict = [repmat(inpict(:,1,:),[1 fw(2) 1]) inpict ...
repmat(inpict(:,end,:),[1 fw(2) 1])];
outpict = [repmat(outpict(1,:,:),[fw(1) 1 1]); outpict; ...
repmat(outpict(end,:,:),[fw(1) 1 1])];
% filter the image
outpict = uint8(conv2(double(outpict),fk,'same'));
% crop off padding
outpict = outpict(fw(1)+1:end-fw(1),fw(2)+1:end-fw(2),:);
imshow(outpict)
Alternatively, MIMT imfilterFB() is more or less a drop-in replacement for imfilter(). Read the documentation and decide if the difference in default padding behavior is a problem for you. If it is, pick the options you want.
inpict = imread('cameraman.tif'); % the image
fk = ones(5)/25; % the filter
% this is part of MIMT
outpict = imfilterFB(inpict,fk);
imshow(outpict)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by