Advertisement
Guest User

Untitled

a guest
May 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. clc
  2. close all
  3. clear all
  4.  
  5. %% Input
  6.  
  7. [I, path] = uitgetfile('*jpg', 'Selectare imagine input');
  8. str = strcat(path, I);
  9. s = imread(str);
  10.  
  11. figure;
  12. imshow(s);
  13. title('Imagine input', 'FontSize', 20);
  14.  
  15. %% Filter
  16.  
  17. num_iter = 10;
  18. delta_t = 1/7;
  19. kappa = 15;
  20. option = 2;
  21. disp('Preprocesare . . .');
  22. inp = anisodiff(s, num_iter, delta_t, kappa, option);
  23. inp = uint8(inp);
  24.  
  25. inp = imresize(inp,[256, 256]);
  26. if size(inp, 3) > 1
  27. inp = rgb2gray(inp);
  28. end
  29. figure;
  30. imshow(inp);
  31. title('Imagine filtrata','Fontsize',20);
  32.  
  33. %% Thresholding
  34.  
  35. sout = imresize(inp, [256, 256]);
  36. t0 = 60;
  37. th = t0 + ((max(inp(:)) + min(inp(:)))./2);
  38. for i = 1:1:size(inp, 1)
  39. for j = 1:1:size(inp, 2)
  40. if inp(i, j) > th
  41. sout(i, j) = 1;
  42. else
  43. sout(i, j)=0;
  44. end
  45. end
  46. end
  47.  
  48. %% Morphological Operation
  49.  
  50. label = bwlabel(sout);
  51. stats = regionprops(logical(sout), 'Solidity', 'Area', 'BoundingBox');
  52. density = [stats.Solidity];
  53. area = [stats.Area];
  54. high_dense_area = density > 0.6
  55. max_area = max(area(high_dense_area));
  56. tumor_label = find(area == max_area);
  57. tumor = ismember(label, tumor-label);
  58.  
  59. if max_area>100
  60. figure;
  61. imshow(tumor)
  62. title('Tumora', 'FontSize', 20);
  63. else
  64. h = msgbox('Fara tumora', 'status');
  65. %disp('Fara tumora');
  66. return;
  67. end
  68.  
  69. %% Bounding Box
  70.  
  71. box = stats(tumor_label);
  72. wantedBox = box.BoundingBox
  73. figure
  74. imshow(inp);
  75. title('Bounding Box', 'FontSize', 20);
  76. hold on
  77. rectangle('Position', wantedBox, 'EdgeColor', 'y');
  78. hold off;
  79.  
  80. %% Tumor Outline - image filling, eroding, subtracting
  81. % erosion the walls by a few pixels
  82.  
  83. dilatationAmount = 5;
  84. rad = floor(dilatationAmount);
  85. [r, c] = size(tumor);
  86. filledImage = imfill(tumor, 'holes');
  87.  
  88. for i = 1:r
  89. for j = 1:c
  90. x1 = i - rad;
  91. x2 = i + rad;
  92. y1 = j - rad;
  93. y2 = j + rad;
  94. if x1 < 1
  95. x1 = 1;
  96. end
  97. if x2 > r
  98. x2 = r;
  99. end
  100. if y1 < 1
  101. y1 = 1;
  102. end
  103. if y2 > c
  104. y2 = c;
  105. end
  106. erodedImage(i, j) = min(min(filledImage(x1:x2, y1:y2)));
  107. end
  108. end
  109. figure
  110. imshow(erodedImage);
  111. title('Imagine erodata', 'FontSize', 20);
  112.  
  113. %% Subtracting eroded image from original BW image
  114.  
  115. tumorOutline = tumor;
  116. tumorOutline(erodedImage) = 0;
  117.  
  118. figure;
  119. imshow(tumorOutline);
  120. title('Contur tumora', 'FontSize', 20);
  121.  
  122.  
  123. %% Inserting the outline in filtered image in green color
  124.  
  125. rgb = inp(:, :, [1 1 1]);
  126. red = rgb(:, :, 1);
  127. red(tumorOutline) = 255;
  128. green = rgb(:, :, 2);
  129. green(tumorOutline) = 0;
  130. blue = rgb(:, :, 3);
  131. blue(tumorOutline) = 0;
  132.  
  133. tumorOutlineInserted(:, :, 1) = red;
  134. tumorOutlineInserted(:, :, 2) = green;
  135. tumorOutlineInserted(:, :, 3) = blue;
  136.  
  137. figure
  138. imshow(tumorOutlineInserted);
  139. title('Tumora detectata', 'FontSize', 20);
  140.  
  141. % Display Together
  142.  
  143. figure
  144. subplot(231);
  145. imshow(s);
  146. title('Imagine Input', 'FontSize', 14);
  147.  
  148. subplot(232);
  149. imshow(inp);
  150. title('Imagine Filtrata', 'FontSize', 14);
  151.  
  152. subplot(233);
  153. imshow(inp);
  154. title('BoundingBox', 'FontSize', 14);
  155.  
  156. hold on;
  157. rectangle('Position, wantedBox, 'EdgeColor', 'y');
  158. hold off;
  159.  
  160. subplot(234);
  161. imshow(tumor);
  162. title('Tumora', 'FontSize', 14);
  163.  
  164. subplot(235);
  165. imshow(tumorOutline);
  166. title('Contur tumora', 'FontSize', 14);
  167.  
  168. subplot(236);
  169. imshow(tumorOutlineInserted);
  170. title('Tumora detectata', 'FontSize',14);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement