区域生长(冈萨雷斯数字图像处理)

来源:互联网 发布:兰特报价软件 编辑:程序博客网 时间:2024/05/16 05:57

区域生长 

regiongrow函数的使用,在使用之前先定义函数功能,http://book.51cto.com/art/201304/391313.htm,

  1. function [g, NR, SI, TI] = regiongrow(f, S, T)  
  2. %REGIONGROW Perform segmentation by region growing.  
  3. %   [G, NR, SI, TI] = REGIONGROW(F, S, T). S can be an array (the  
  4. %   same size as F) with a 1 at the coordinates of every seed point  
  5. %   and 0s elsewhere. S can also be a single seed value. Similarly,  
  6. %   T can be an array (the same size as F) containing a threshold  
  7. %   value for each pixel in F. T can also be a scalar, in which case  
  8. %   it becomes a global threshold. All values in S and T must be in  
  9. %   the range [0, 1]  
  10. %  
  11. %   G is the result of region growing, with each region labeled by a  
  12. %   different integer, NR is the number of regions, SI is the final  
  13. %   seed image used by the algorithm, and TI is the image consisting  
  14. %   of the pixels in F that satisfied the threshold test, but before  
  15. %   they were processed for connectivity.  
  16.  
  17. if = tofloat(f);  
  18. % If S is a scalar, obtain the seed image.  
  19. if numel(S) == 1  
  20.    SI = f == S;  
  21.    SS1 = S;  
  22. else  
  23.    % S is an array. Eliminate duplicate, connected seed locations  
  24.    % to reduce the number of loop executions in the following  
  25.    % sections of code.  
  26.    SI = bwmorph(S, 'shrink', Inf);  
  27.    S1 = f(SI); % Array of seed values.  
  28. end  
  29.  
  30. TI = false(size(f));  
  31. for K = 1:length(S1)  
  32.    seedvalue = S1(K);  
  33.    S = abs(f ? seedvalue) <= T; % Re-use variable S.  
  34.    TITI = TI | S;  
  35. end  
  36. % Use function imreconstruct with SI as the marker image to  
  37. % obtain the regions corresponding to each seed in S. Function  
  38. % bwlabel assigns a different integer to each connected region.  
  39. [g, NR] = bwlabel(imreconstruct(SI, TI));  
bwmorph函数的作用,提取二进制图像的轮廓,对二值图象的形态学操作,http://blog.csdn.net/a1075863454/article/details/45646187


i=imread('X-ray.png');
I1 = rgb2gray(i);
figure(1);imshow(I1);
% i=doulbe(i);
[m,n]=size(I1);
S=1;
T=0.26;
[g, NR, SI, TI ]=regiongrow(I1,S,T);
figure(2);imshow(g);title('区域增长');
figure(3);imshow(SI);
figure(4);imshow(TI);

然后对定义regiongrow里的tofloat,https://zhidao.baidu.com/question/499990534173948084.html,就可以运行程序了。











































































































原创粉丝点击