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

1 Ansicht (letzte 30 Tage)
PinYu Chen
PinYu Chen am 23 Mai 2022
Bearbeitet: DGM am 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 Kommentare
Stephen23
Stephen23 am 23 Mai 2022
What do you expect the 'parent' option to achieve? I do not see it mentioned in the IMFILTER documentation.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 23 Mai 2022
Bearbeitet: Jan am 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 Kommentare
PinYu Chen
PinYu Chen am 24 Mai 2022
Thanks, but I changed the code and it still doesn't work.
DGM
DGM am 24 Mai 2022
Bearbeitet: DGM am 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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by