How to add filter just foreground and another filter to background?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ZeZe Joscy
am 7 Dez. 2021
Beantwortet: yanqi liu
am 8 Dez. 2021
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.
0 Kommentare
Akzeptierte Antwort
yanqi liu
am 8 Dez. 2021
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matched Filter and Ambiguity Function 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!





