Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. exer 14
  2.  
  3. clear, clc, close all;
  4. img = imread('peter.png');
  5. level = 105;
  6. bwImg = img < level;
  7. holeImg = img .* uint8(bwImg);
  8. subplot(1, 3, 1), imshow(img), title('Original image');
  9. subplot(1, 3, 2), imshow(bwImg), title('Thresholded Image');
  10. subplot(1, 3, 3), imshow(holeImg), title('Binary Map \times Original');
  11. imwrite(bwImg, 'Graylevel_Thresholding_thresholded.png');
  12. imwrite(holeImg, 'Graylevel_Thresholding_blend.png');
  13.  
  14. exer 15
  15.  
  16. clear, clc, close all;
  17. img = imread('brain.jpg');
  18. level = graythresh(img);
  19. otsuThresh = round(level * 255);
  20. bwImg = im2bw(img, level);
  21. subplot(1, 4, 1), imshow(img), title('Original image');
  22. subplot(1, 4, 2), imshow(bwImg), title('Globally Thresholded Image');
  23. subplot(1, 4, 3), imshow(1-bwImg .* im2double(img));
  24. title('Overlay');
  25. subplot(1, 4, 4),[counts,x] = imhist(img);
  26. bar(x, counts); hold on;
  27. h = plot(otsuThresh*ones(1,100), linspace(0,max(counts)), 'r-');
  28. title ('Graylevel Histogram');
  29. axis([0 255 0 max(counts)]);
  30. set(gca, 'FontSize', 10);
  31. imwrite(bwImg, 'Globally_Thresholding_bw.png');
  32. saveas(gcf, 'Global_Thresholding_hist.png')
  33.  
  34. exer 18
  35.  
  36. clear, clc, close all;
  37. img = imread('fish.png');
  38. level = graythresh(img);
  39. bwImg = 1- im2bw(img, level);
  40. L = bwlabel(bwImg, 8);
  41. rgbLabel = label2rgb(L, 'jet', 'k');
  42. subplot(1, 3, 1), imshow(img), title('Original image');
  43. subplot(1, 3, 2), imshow(bwImg), title('Binarize image');
  44. subplot(1, 3, 3), imshow(rgbLabel); title('Labeled Regions');
  45. imwrite(bwImg, ' Region_Labeling_bw.png');
  46. imwrite(rgbLabel, ' Region_Labeling_rgbLabel.png');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement