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

2 views (last 30 days)
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

Answers (1)

Jan
Jan on 23 May 2022
Edited: Jan on 23 May 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 Comments
DGM
DGM on 24 May 2022
Edited: DGM on 24 May 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)

Sign in to comment.

Categories

Find more on Statistics and Machine Learning 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!