【50】 【图像处理】基于遗传算法的图像边缘检测
2021-03-08 08:30
标签:diff iter led cli jpg nim ati mic size function gakmeans?clc;close all; clear all;?% sds - sampled dataset global sds;?[im,map]=imread(‘ant.jpg‘);if ( size(im,3)==3) im=rgb2gray(im);end?im=im2double(im);[row,col]=size(im);nc=5;?L= row*col;rns=(10/100)*L; rp=randperm(L);sds=im(rp(1:rns));?options=gaoptimset(‘PopulationSize‘,20,‘PopulationType‘,‘doubleVector‘, ... ‘CrossoverFraction‘,0.7, ‘Generations‘,100,‘EliteCount‘,2, ... ‘SelectionFcn‘, @selectionroulette,‘CrossoverFcn‘,@crossoverarithmetic,... ‘MutationFcn‘,@mutationadaptfeasible,‘PlotFcns‘,@gaplotbestf) ;? % lower bound limit lb=zeros(nc,1);% upper bound limitub=ones(nc,1);?[gics,gfv,exf] =ga(@objfunc,nc,[],[],[],[],lb,ub,[],options);?[idx,cs,egr]=kmeanseg(im,gics);gsim=coloring(cs,idx);gsim=reshape(gsim,row,col,3);?figure;imshow(gsim);title(‘GA-Kmeans‘);function egr=objfunc(cs)?global sds nc = size(cs,2); [row,col]=size(sds); D=zeros(row,col,nc); % Euclidean distance between centroids and image‘s pixel for c=1: nc D(:,:,c)= (sds - cs(c)).^2 ; end % assign members (image pixels) to clusters [mv,~]=min(D,[],3); egr=sum(mv(:)); function gsim=coloring(cs,idx)?nc = length(cs);[~,ind]=sort(cs);gidx=zeros(size(idx));?for s=1: nc gidx(idx==ind(s)) =s; end?colors = hsv(nc);gsim= colors(gidx,:); function [idx,cs,egr]=kmeanseg(im,cs)?%number of IterationT= 50; t=0; ?nc=length(cs);[row,col]=size(im);D=zeros(row,col,nc);?pcs=cs;egr =[];eps=1.e-8; cmx=1;?while ( t 注:完整代码或者代写添加QQ1575304183 【50】 【图像处理】基于遗传算法的图像边缘检测 标签:diff iter led cli jpg nim ati mic size 原文地址:https://www.cnblogs.com/homeofmatlab/p/14207441.html
下一篇:3. java的数据类型
文章标题:【50】 【图像处理】基于遗传算法的图像边缘检测
文章链接:http://soscw.com/index.php/essay/61727.html