How to add filter just foreground and another filter to background?

4 ビュー (過去 30 日間)
ZeZe Joscy
ZeZe Joscy 2021 年 12 月 7 日
回答済み: yanqi liu 2021 年 12 月 8 日
Hello, i am trying to add filter to foreground and another filter to background:
I had an gray scale image which background is blur and foreground has an object. And i separated my image with iterative optimal threshold algorithm. Here is my code:
I=imread('a.png');
A=stdfilt(I);
T=1;
%% G1 is foreground, G2 is background %%
for i=1:16
G1=T>A;
G2=T<=A;
m1=mean(A(G1));
m2=mean(A(G2));
Tnew=(m1+m2)/2;
T=Tnew;
end
Here i am trying to add L filter to just foreground but it doesn't work.
L=[-1 -1 -1;-1 8 -1;-1 -1 -1];
P=imfilter(G1,L);
R=I+P;
And here i am trying to add Gfilter to just background but it also doesn't work.
G=1/16*[1 2 1;2 4 2;1 2 1];
J=imfilter(I(G2),G);
Result=J+R;
I know i am wrong somewhere but i also don't know how to fix it.

採用された回答

yanqi liu
yanqi liu 2021 年 12 月 8 日
clc; clear all; close all;
I=imread('rice.png');
A=stdfilt(I);
T=1;
% G1 is foreground, G2 is background %%
for i=1:16
G1=T>A;
G2=T<=A;
m1=mean(A(G1));
m2=mean(A(G2));
Tnew=(m1+m2)/2;
T=Tnew;
end
figure; imshow(G1, []);
figure; imshow(G2, []);
G1 = I.*uint8(G1);
G2 = I.*uint8(G2);
figure; imshow(G1, []);
figure; imshow(G2, []);
% add L filter to just foreground
L=[-1 -1 -1;-1 8 -1;-1 -1 -1];
P=imfilter(G1,L);
R=I+P;
% add Gfilter to just background
G=1/16*[1 2 1;2 4 2;1 2 1];
J=imfilter(G2,G);
Result=J+R;
% imshow
figure; imshow(R, []);
figure; imshow(Result, []);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by