关闭

matlab图像提取

306人阅读 评论(0) 收藏 举报
分类:

 


  1. close all;
  2. clear all;
  3. clc;
  4. I_rgb=imread ('D:\科研室资料\图片1\图片\clothes_100065.jpg')
  5. figure(1);imshow(I_rgb);title('原始图像');
  6. %去噪
  7. filter=ones(5,5);
  8. filter=filter/sum(filter(:));
  9. denoised_r=conv2(I_rgb(:,:,1),filter,'same');
  10. denoised_g=conv2(I_rgb(:,:,2),filter,'same');
  11. denoised_b=conv2(I_rgb(:,:,3),filter,'same');
  12. denoised_rgb=cat(3, denoised_r, denoised_g, denoised_b);
  13. D_rgb=uint8(denoised_rgb);
  14. figure();imshow(D_rgb);title('去噪后图像');%去噪后的结果
  15. %将彩色图像从RGB转化到lab彩色空间
  16. C =makecform('srgb2lab'); %设置转换格式
  17. I_lab= applycform(D_rgb, C);
  18. %进行K-mean聚类将图像分割成2个区域
  19. ab =double(I_lab(:,:,2:3)); %取出lab空间的a分量和b分量
  20. nrows= size(ab,1);
  21. ncols= size(ab,2);
  22. ab =reshape(ab,nrows*ncols,2);
  23. nColors= 2; %分割的区域个数为2
  24. [cluster_idx,cluster_center] =kmeans(ab,nColors,'distance','sqEuclidean','Replicates',2); %重复聚类2次
  25. pixel_labels= reshape(cluster_idx,nrows,ncols);
  26. %显示分割后的各个区域
  27. segmented_images= cell(1,3);
  28. rgb_label= repmat(pixel_labels,[1 1 3]);
  29. for k= 1:nColors
  30. color = I_rgb;
  31. color(rgb_label ~= k) = 0;
  32. segmented_images{k} = color;
  33. end
  34. figure(),imshow(segmented_images{1}),title('分割结果——区域1');
  35. figure(),imshow(segmented_images{2}),title('分割结果——区域2');
  36. %计算分割后图像的rgb特征值
  37. val_d_red=mean2(segmented_images{1}(:,:,1));
  38. val_d_green=mean2(segmented_images{1}(:,:,2));
  39. val_d_blue=mean2(segmented_images{1}(:,:,3));
  40. disp(sprintf('[%0.3f,%0.3f,%0.3f]',val_d_red,val_d_green,val_d_blue));

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:45917次
    • 积分:565
    • 等级:
    • 排名:千里之外
    • 原创:41篇
    • 转载:10篇
    • 译文:1篇
    • 评论:1条
    最新评论