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

1 次查看(过去 30 天)
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

回答(1 个)

Jan
Jan 2022-5-23
编辑:Jan 2022-5-23
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 个评论
DGM
DGM 2022-5-24
编辑:DGM 2022-5-24
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)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by