|
自己的两个写起来就感觉比较有趣
用遗传算法进行前景背景分割(待更新
模糊算法Fuzzy进行边缘提取
经常运用在PID控制中的FUZZY在边缘提取上也可以有所应用。我们先进行高斯滤波去噪并且拉高梯度,然后规定如下的规则
If top is zero AND right is zero, THEN this pixel is NOT edge. If top is zero AND left is zero, THEN this pixel is NOT edge. If below is zero AND right is zero, THEN this pixel is NOT edge. If below is zero AND left is zero, THEN this pixel is NOT edge. ELSE is edge.
用这样的方式获得图片的边缘梯度从而实现边缘提取。很有趣,Fuzzy还可以运用到更多的地方,比如神经网络。
附上MatLab代码,手机编辑暂时格式乱一点…
%% function [W1,W2,W3,W4,B] = Fuzzy_Knowledge_Filters(Intensity) for x = 1:1:3 for y = 1:1:3 if((Intensity(x,y) <= 0.2) &&(Intensity(x,y) >= -0.2)) Intensity(x,y) = exp(-20*Intensity(x,y).*Intensity(x,y)); %Use the Guass method to make it clear else Intensity(x,y) = 0; end end end W1 = min(Intensity(1,2),Intensity(2,3)); %If a AND b use the minimum W2 = min(Intensity(2,3),Intensity(3,2)); W3 = min(Intensity(3,2),Intensity(2,1)); W4 = min(Intensity(2,1),Intensity(1,2)); B = min(min(1-W1,1-W2),min(1-W3,1-W4)); end
%% ---------Using Fuzzy for Spatial Filters--------------- close all; clear all; clc; f = imread(&#39;&#39;); f = mat2gray(f,[0 255]); [M,N]=size(f); f_Ex = zeros(M+2,N+2); for x = 1:1:M for y = 1:1:N f_Ex(x+1,y+1) = f(x,y); end end z = zeros (3,3); g = zeros (M+2,N+2); for x = 2:1:M+1 for y = 2:1:N+1 z(1,1) = f_Ex(x-1,y-1) - f_Ex(x,y); z(1,2) = f_Ex(x-1,y) - f_Ex(x,y); z(1,3) = f_Ex(x-1,y+1) - f_Ex(x,y); z(2,1) = f_Ex(x,y-1) - f_Ex(x,y); z(2,2) = f_Ex(x,y) - f_Ex(x,y); z(2,3) = f_Ex(x,y+1) - f_Ex(x,y); z(3,1) = f_Ex(x+1,y-1) - f_Ex(x,y); z(3,2) = f_Ex(x+1,y) - f_Ex(x,y); z(3,3) = f_Ex(x+1,y+1) - f_Ex(x,y); [W1,W2,W3,W4,B] = Fuzzy_Knowledge_Filters(z); V1 = 0.8 * W1 + 0.2; V2 = 0.8 * W2 + 0.2; V3 = 0.8 * W3 + 0.2; V4 = 0.8 * W4 + 0.2; V5 = 0.8 - (0.8 * B); g(x,y) = ((W1*V1) + (W2*V2) + (W3*V3) + (W4*V4) + (B*V5))/(W1+W2+W3+W4+B); end end figure(); subplot(1,2,1); imshow(f,[0 1]); xlabel(&#39;a).Original Image&#39;); subplot(1,2,2); imshow(g,[0 1]); xlabel(&#39;b).Result of fuzzy&#39;);
<hr/> |
|