Hello Mat

 找回密码
 立即注册
查看: 6420|回复: 0

灰度共生矩阵GLCM、图像均值、方差、熵、Percentile mean and SD、Kurtosis、Skewness

[复制链接]

1323

主题

1551

帖子

0

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22647
发表于 2017-5-6 13:25:40 | 显示全部楼层 |阅读模式
灰度共生矩阵GLCM、图像均值、方差、熵、Percentile mean and SD、Kurtosis、Skewness等特征:
  1. function feature = feature_extracted2( im2,x,y )
  2. [h,w] = size(im2);
  3. % Gray-level histogram features
  4. % [n_count,x_value]  = imhist(im2);
  5. Nt = h*w;
  6. % prob = n_count./Nt;     % Pi概率值
  7. % x_value = prob;
  8. % x_value = im2(:);

  9. for i=1:length(x)
  10.     x_value(i) = im2(x(i),y(i));
  11. end

  12. mean1 = mean(x_value);  % 均值
  13. SD1 = std(x_value);     % 方差
  14. % Percentile mean and SD
  15. x_value1 = sort(x_value,'ascend');
  16. mean_beta_10 = mean( x_value1(floor(0.90*length(x_value1)):end ) );
  17. mean_beta_25 = mean( x_value1(floor(0.75*length(x_value1)):end ) );
  18. mean_beta_50 = mean( x_value1(floor(0.50*length(x_value1)):end ) );
  19. SD_beta_10 = std( x_value1(floor(0.90*length(x_value1)):end ) );
  20. SD_beta_25 = std( x_value1(floor(0.75*length(x_value1)):end ) );
  21. SD_beta_50 = std( x_value1(floor(0.50*length(x_value1)):end ) );
  22. % Kurtosis
  23. % kurtosis1 = sum((x_value-mean1).^4)/Nt ./ sqrt( sum((x_value-mean1).^2)./Nt ).^4;
  24. % kurtosis1 = sum((x_value-mean1).^4) ./ sqrt( sum((x_value-mean1).^2) ).^4;
  25. % Skewness
  26. % skewness1 = sum((x_value-mean1).^3)/Nt ./ sqrt( sum((x_value-mean1).^2)./Nt ).^3;
  27. % skewness1 = sum((x_value-mean1).^3) ./ sqrt( sum((x_value-mean1).^2) ).^3;
  28. kurtosis1 = kurtosis(double(x_value));
  29. skewness1 = skewness(double(x_value));

  30. % Gray-Level Co-Occurrence Matrix(GLCM)
  31. %                    Angle     OFFSET
  32. %                    -----     ------  
  33. %                    0         [0 D]   
  34. %                    45        [-D D]
  35. %                    90        [-D 0]
  36. %                    135       [-D -D]  
  37. glcms_0 = graycomatrix(im2, 'offset', [0 1]);       % Angle = 0
  38. glcms_45 = graycomatrix(im2, 'offset', [-1 1]);     % Angle = 45
  39. glcms_90 = graycomatrix(im2, 'offset', [-1 0]);     % Angle = 90
  40. glcms_135 = graycomatrix(im2, 'offset', [-1 -1]);   % Angle = 135
  41. stats_0 = graycoprops(glcms_0, 'all');
  42. stats_45 = graycoprops(glcms_45, 'all');
  43. stats_90 = graycoprops(glcms_90, 'all');
  44. stats_135 = graycoprops(glcms_135, 'all');

  45. Contrast_0 = stats_0.Contrast;
  46. Correlation_0 = stats_0.Correlation;
  47. Energy_0 = stats_0.Energy;
  48. Homogeneity_0 = stats_0.Homogeneity;
  49. % 求解熵
  50. tGLCM = glcms_0./sum(glcms_0(:));
  51. entropy_0 = -sum(sum(tGLCM.*log(tGLCM+eps)));

  52. Contrast_45 = stats_45.Contrast;
  53. Correlation_45 = stats_45.Correlation;
  54. Energy_45 = stats_45.Energy;
  55. Homogeneity_45 = stats_45.Homogeneity;
  56. % 求解熵
  57. tGLCM = glcms_45./sum(glcms_45(:));
  58. entropy_45 = -sum(sum(tGLCM.*log(tGLCM+eps)));

  59. Contrast_90 = stats_90.Contrast;
  60. Correlation_90 = stats_90.Correlation;
  61. Energy_90 = stats_90.Energy;
  62. Homogeneity_90 = stats_90.Homogeneity;
  63. % 求解熵
  64. tGLCM = glcms_90./sum(glcms_90(:));
  65. entropy_90 = -sum(sum(tGLCM.*log(tGLCM+eps)));

  66. Contrast_135 = stats_135.Contrast;
  67. Correlation_135 = stats_135.Correlation;
  68. Energy_135 = stats_135.Energy;
  69. Homogeneity_135 = stats_135.Homogeneity;
  70. % 求解熵
  71. tGLCM = glcms_135./sum(glcms_135(:));
  72. entropy_135 = -sum(sum(tGLCM.*log(tGLCM+eps)));

  73. feature = [mean1,SD1,mean_beta_10,mean_beta_25,mean_beta_50,SD_beta_10,SD_beta_25,SD_beta_50,...
  74.     kurtosis1,skewness1,...
  75.     Contrast_0,Correlation_0,Energy_0,Homogeneity_0,entropy_0...
  76.     Contrast_45,Correlation_45,Energy_45,Homogeneity_45,entropy_45...
  77.     Contrast_90,Correlation_90,Energy_90,Homogeneity_90,entropy_90...
  78.     Contrast_135,Correlation_135,Energy_135,Homogeneity_135,entropy_135];
复制代码
图像滤波函数:
  1. function im5 = freqfilter2(im1,delta)
  2. % 滤波器
  3. % input:
  4. %     M,N:频域滤波器的尺寸
  5. %     delta:带阻滤波器的截止频率
  6. % output:
  7. %       H:M x N的矩阵,表示频域滤波器矩阵,数据类型为double,
  8. if ~isa(im1,'double')
  9.     im1 = double(im1)/255;
  10. end
  11. % im2 = fft2(im1);      % 傅里叶变换
  12. % im3 = fftshift(im2);  % 中心化

  13. % [N1, N2] = size(im3);
  14. for i = 1:3
  15.     for j = 1:3
  16.         h(i,j) = -1/3.1415926/(delta.^4).*(1-(i.^2+j.^2)/2/delta/delta).*exp( -((i.^2+j.^2)./2/delta/delta) );
  17.     end
  18. end
  19. im5 = conv2(im1,h,'same');

  20. % result = ifftshift(result);    % 反中心化
  21. % im4 = ifft2(result);           % 反变换
  22. % % im5 = im2uint8(real(im4));     % 滤波图像
  23. % im5 = abs(real(im4));     % 滤波图像

  24. minV = min(min(im5));
  25. maxV = max(max(im5));
  26. im5 = 255.0*(im5-minV)./(maxV-minV);

  27. end
复制代码
图像特征求解,主程序:
  1. clc,clear,close all
  2. warning off
  3. im = dicomread('例图2.dcm');
  4. im = mat2gray(im);
  5. % figure(1),imshow(im)
  6. % 扣出感兴趣区域
  7. bw = im>0;
  8. % figure(2),imshow(bw)
  9. [x,y] = find(bw==1);
  10. im1 = im(min(x):max(x),min(y):max(y));
  11. bw = im2bw(im1);
  12. [x,y] = find(bw==1);
  13. minV = min(min(im1));
  14. maxV = max(max(im1));
  15. im1 = 255.0*(im1-minV)./(maxV-minV);
  16. % im1 = im2uint8(im1);
  17. figure(3),imshow(im1,[])
  18. [h,w] = size(im1);

  19. delta = [0.0,1.0,1.5,2.0,2.5];
  20. feature_total = [];
  21. for i = 1:length(delta)
  22.    
  23.     if isequal(delta(i),0)
  24.         im2 = im1;
  25.     else
  26.         % 图像滤波
  27.         im2 = freqfilter2(im1,delta(i));
  28.     end
  29.     % 特征求解
  30.     feature = feature_extracted2( im2,x,y );
  31.    
  32.     figure,imshow(im2,[])
  33.     feature2(i,:) = feature;
  34.     feature_total = [feature_total,feature];
  35.    
  36. end
  37. %% 特征绘图
  38. figure(10),plot(feature_total,'ro-','linewidth',2);
  39. grid on
复制代码

参考资料:【1】结肠癌 淋巴转移 nomogram JCO:http://pan.baidu.com/s/1cgYzO6
【2】Development and validation of a radiomics nomogram for preoperative predicting lymph node metastasis in colorectal cancer :http://pan.baidu.com/s/1jHDBSEU
【3】图像:http://pan.baidu.com/s/1nuXmiXr

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-11-25 13:46 , Processed in 0.215339 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表