路标识别与提取(采用聚类方法)(C-means)(K-means)

  • w9_215483
    了解作者
  • Python
    开发工具
  • 4.5MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-02-28 09:55
    上传日期
路标识别与提取(采用聚类方法)(C-means)(K-means)能对路边进行有效识别和提取,采用MATLAB 语言编写。
聚类.zip
  • 聚类
  • 2.jpg
    137.6KB
  • 1.jpg
    183.9KB
  • 3.jpg
    128.3KB
  • fizzyC_RGB_3.fig
    146.6KB
  • C_mean.m
    9.2KB
  • C_mean.asv
    6KB
  • fuzzyC2.fig
    1.9MB
  • fuzzyC1.fig
    2MB
内容介绍
%C均值聚类算法 clear clc [filename,pathname] = uigetfile('*.jpg','读取图片文件');%选择图片文件 if isequal(filename,0) %判断是否选择 msgbox('没有选择任何图片'); else pathfile = fullfile(pathname,filename); %获得图片路径 RGB = imread(pathfile); %将图片读入矩阵 YUV = rgb2ycbcr(RGB);%转成YUV figure; imshow(YUV); %绘制图片 end size_image = size(YUV(:,:,1)); YUV = double(YUV); i = 1:1:size_image(1); j = 1:1:size_image(2); data = zeros(size_image(1)*size_image(2),2); for i = 1:size_image(1); %data为n*m矩阵,n为样本点个数,m为么个特征的维数 for j = 1:size_image(2); data(j+(i-1)*size_image(2),1) = YUV(i,j,1); data(j+(i-1)*size_image(2),2) = YUV(i,j,3); end end [center,U,obj_fcn] = fcm(data,4); %模糊C聚类算法 figure plot(data(:,1),data(:,2),'o'); hold on; maxU = max(U); index1 = find(U(1,:) == maxU); index2 = find(U(2,:) == maxU); index3 = find(U(3,:) == maxU); index4 = find(U(4,:) == maxU); plot(data(index1,1),data(index1,2),'og'); plot(data(index2,1),data(index2,2),'or'); plot(data(index3,1),data(index3,2),'ob'); plot(data(index4,1),data(index4,2),'oy'); %画聚类中心 plot(center(1,1),center(1,2),'xr','MarkerSize',15,'LineWidth',3); plot(center(2,1),center(2,2),'xb','MarkerSize',15,'LineWidth',3); plot(center(3,1),center(3,2),'xy','MarkerSize',15,'LineWidth',3); plot(center(4,1),center(4,2),'xk','MarkerSize',15,'LineWidth',3); title('分类结果'); hold off; figure result = zeros(size_image(1),size_image(2),3)+255; a1 = fix(index1/size_image(2)); b1 = rem(index1,size_image(2)); sizea1 = size(a1); sizeb1 = size(b1); %画第一类点 for i = 1:size_image(1); temp_a1 = any(a1==i); if(temp_a1==1) pos_a1 = find(a1 == i); size_pos_a1 = size(pos_a1); b_block = b1(pos_a1(1):(pos_a1(1)+size_pos_a1(2)-1)); for j = 1:size_image(2); temp_b1 = any(b_block == j); if(temp_b1 == 1) result(i,j,:) = [1,0,0]; end end end end a2 = fix(index2/size_image(2)); b2 = rem(index2,size_image(2)); sizea2 = size(a2); sizeb2 = size(b2); %画第二类点 for i = 1:size_image(1); temp_a2 = any(a2==i); if(temp_a2==1) pos_a2 = find(a2==i); size_pos_a2 = size(pos_a2); b_block = b2(pos_a2(1):(pos_a2(1)+size_pos_a2(2)-1)); for j = 1:size_image(2); temp_b2 = any(b_block == j); if(temp_b2 == 1) result(i,j,:) = [0,1,0]; end end end end a3 = fix(index3/size_image(2)); b3 = rem(index3,size_image(2)); sizea3 = size(a3); sizeb3 = size(b3); %画第三类点 for i = 1:size_image(1); temp_a3 = any(a3==i); if(temp_a3==1) pos_a3 = find(a3==i); size_pos_a3 = size(pos_a3); b_block = b3(pos_a3(1):(pos_a3(1)+size_pos_a3(2)-1)); for j = 1:size_image(2); temp_b3 = any(b_block == j); if(temp_b3 == 1) result(i,j,:) = [0,0,1]; end end end end imshow(result); figure BW1 = im2bw(result); BW = bwperim(BW1); imshow(BW) % I = medfilt2(L); %采用二维中值滤波函数medfilt2对受椒盐噪声干扰的图像滤波 % figure % imshow(I) % title('去噪之后的图像') switch filename case '1.jpg' %------------------------------------------------------------------------ % AL-AZHAR UNIVERSITY % FACULTY OF ENGINEERING % SYSTEMS & COMPUTERS ENGINEERING Department %------------------------------------------------------------------------ % Author : Ahmed Samieh Abd El-Wahab % Date : 14 December 2006 %------------------------------------------------------------------------ % Shapes Classifier % Step 1: Read image Read in % Step 2: Convert image from rgb to gray % Step 3: Threshold the image % Step 4: Invert the Binary Image % Step 5: Find the boundaries Concentrate % Step 6: Determine Shapes properties % Step 7: Classify Shapes according to properties % Square = 3 % Rectangular = 2 % Circle = 1 % UNKNOWN = 0 %------------------------------------------------------------------------ % Step 2: Convert image from rgb to gray % Step 4: Invert the Binary Image BW = ~ BW; figure, imshow(BW), title('Inverted Binary Image'); % Step 5: Find the boundaries Concentrate only on the exterior boundaries. % Option 'noholes' will accelerate the processing by preventing % bwboundaries from searching for inner contours. [B,L] = bwboundaries(BW, 'noholes'); % Step 6: Determine objects properties STATS = regionprops(L, 'all'); % we need 'BoundingBox' and 'Extent' % Step 7: Classify Shapes according to properties % Square = 3 = (1 + 2) = (X=Y + Extent = 1) % Rectangular = 2 = (0 + 2) = (only Extent = 1) % Circle = 1 = (1 + 0) = (X=Y , Extent < 1) % UNKNOWN = 0 figure imshow(RGB), title('Results'); hold on for i = 1 : length(STATS) W(i) = uint8(10<abs(STATS(i).BoundingBox(3)-STATS(i).BoundingBox(4)) < 50); W(i) = W(i) + 2 * uint8((STATS(i).Extent - 1) == 0 ); centroid = STATS(i).Centroid; switch W(i) case 1 plot(centroid(1),centroid(2),'wO'); case 2 plot(centroid(1),centroid(2),'wX'); case 3 plot(centroid(1),centroid(2),'wS'); end end case {'2.jpg','3.jpg'} step_r = 1; step_angle = 0.05; r_min = 50; r_max = 60; thresh = 0.95; % %%%%%%%%%%%%%%%%%%%%%%%%%% % input % BW:二值图像; % step_r:检测的圆半径步长 % step_angle:角度步长,单位为弧度 % r_min:最小圆半径 % r_max:最大圆半径 % p:阈值,0,1之间的数 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % output % hough_space:参数空间,h(a,b,r)表示圆心在(a,b)半径为r的圆上的点数 % hough_circl:二值图像,检测到的圆 % para:检测到的圆的圆心、半径 [m,n] = size(BW); size_r = round((r_max-r_min)/step_r)+1; size_angle = round(2*pi/step_angle); hough_space = zeros(m,n,size_r); [rows,cols] = find(BW); ecount = size(rows); % Hough变换 % 将图像空间(x,y)对应到参数空间(a,b,r) % a = x-r*cos(angle) % b = y-r*sin(angle) for i=1:ecount for r=1:size_r for k=1:size_angle a = round(rows(i)-(r_min+(r-1)*step_r)*cos(k*step_angle)); b = round(cols(i)-(r_min+(r-1)*step_r)*sin(k*step_angle)); if(a rel='nofollow' onclick='return false;'>0&a<=m&b>0&b<=n) hough_space(a,b,r) = hough_space(a,b,r)+1; end end end end % 搜索超过阈值的聚集点 max_para = max(max(max(hough_space))); index = find(hough_space>=max_para*thresh); length = size(index); hough_circle = false(m,n); for i=1:ecount for k=1:length par3 = floor(index(k)/(m*n))+1; par2 = floor((index(k)-(par3-1)*(m*n))/m)+1; par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m; if((rows(i)-par1)^2+(cols(i)-par2)^2<(r_min+(par3-1)*step_r)^2+5&... (rows(i)-par1)^2+(cols(i)-par2)^2>(r_min+(par3-1)*step_r)^2-5)
评论
    相关推荐
    • matlabcnhelp.rar
      matlab中文帮助很难找的,快速下载
    • MobilePolice.rar
      移动警察,车牌识别,车牌定位系统源代码,已经运用在移动车载稽查系统中。
    • SVM(matlab).rar
      支持向量机(SVM)实现的分类算法源码[matlab]
    • svm.zip
      用MATLAB编写的svm源程序,可以实现支持向量机,用于特征分类或提取
    • Classification-MatLab-Toolbox.rar
      模式识别matlab工具箱,包括SVM,ICA,PCA,NN等等模式识别算法,很有参考价值
    • VC++人脸定位实例.rar
      一个经典的人脸识别算法实例,提供人脸五官定位具体算法及两种实现流程.
    • QPSK_Simulink.rar
      QPSK的Matlab/Simulink的调制解调仿真系统,给出接收信号眼图及系统仿真误码率,包含载波恢复,匹配滤波,定时恢复等重要模块,帮助理解QPSK的系统
    • LPRBPDemo2009KV.rar
      车牌识别,神经网络算法,识别率高达95%,识别时间低于80ms。
    • MODULATION.RAR
      这个源程序代码包提供了通信系统中BPSK,QPSK,OQPSK,MSK,MSK2,GMSK,QAM,QAM16等调制解调方式 用matlab的实现,以及它们在AWGN和Rayleigh信道下的通信系统实现及误码率性能
    • algorithms.rar
      十大算法论文,包括遗传算法,模拟退火,蒙特卡罗法等等,对于初学者很有帮助!!