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

2 ビュー (過去 30 日間)
PinYu Chen
PinYu Chen 2022 年 5 月 23 日
編集済み: DGM 2022 年 5 月 24 日
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 件のコメント
Stephen23
Stephen23 2022 年 5 月 23 日
What do you expect the 'parent' option to achieve? I do not see it mentioned in the IMFILTER documentation.
PinYu Chen
PinYu Chen 2022 年 5 月 23 日
Place the image on app.UIAxes_3.

サインインしてコメントする。

回答 (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 件のコメント
PinYu Chen
PinYu Chen 2022 年 5 月 24 日
Thanks, but I changed the code and it still doesn't work.
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 Center および File ExchangeStatistics 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