Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exer 14
- clear, clc, close all;
- img = imread('peter.png');
- level = 105;
- bwImg = img < level;
- holeImg = img .* uint8(bwImg);
- subplot(1, 3, 1), imshow(img), title('Original image');
- subplot(1, 3, 2), imshow(bwImg), title('Thresholded Image');
- subplot(1, 3, 3), imshow(holeImg), title('Binary Map \times Original');
- imwrite(bwImg, 'Graylevel_Thresholding_thresholded.png');
- imwrite(holeImg, 'Graylevel_Thresholding_blend.png');
- exer 15
- clear, clc, close all;
- img = imread('brain.jpg');
- level = graythresh(img);
- otsuThresh = round(level * 255);
- bwImg = im2bw(img, level);
- subplot(1, 4, 1), imshow(img), title('Original image');
- subplot(1, 4, 2), imshow(bwImg), title('Globally Thresholded Image');
- subplot(1, 4, 3), imshow(1-bwImg .* im2double(img));
- title('Overlay');
- subplot(1, 4, 4),[counts,x] = imhist(img);
- bar(x, counts); hold on;
- h = plot(otsuThresh*ones(1,100), linspace(0,max(counts)), 'r-');
- title ('Graylevel Histogram');
- axis([0 255 0 max(counts)]);
- set(gca, 'FontSize', 10);
- imwrite(bwImg, 'Globally_Thresholding_bw.png');
- saveas(gcf, 'Global_Thresholding_hist.png')
- exer 18
- clear, clc, close all;
- img = imread('fish.png');
- level = graythresh(img);
- bwImg = 1- im2bw(img, level);
- L = bwlabel(bwImg, 8);
- rgbLabel = label2rgb(L, 'jet', 'k');
- subplot(1, 3, 1), imshow(img), title('Original image');
- subplot(1, 3, 2), imshow(bwImg), title('Binarize image');
- subplot(1, 3, 3), imshow(rgbLabel); title('Labeled Regions');
- imwrite(bwImg, ' Region_Labeling_bw.png');
- imwrite(rgbLabel, ' Region_Labeling_rgbLabel.png');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement