彩色影像二值化函式(matlab)

追風少年101發表於2020-10-24
%讀資料
subplot(1, 2, 1);
a = imread('shiyan.jpg');
imshow(a);
title('原圖');

%彩色影像二值化
subplot(1, 2, 2);
thresh = graythresh(a);%自動確定閾值
b = im2bw(a, thresh);
imshow(b);
title('二值化');

%生成bmp格式的二值影像
str2 = 'shiyan2';
str3 = '.jpg';
save_path = [str2, str3];
imwrite(b, save_path);		% 這裡可以寫成imwrite(b, stract('C:\路徑\', 'binary_image2', '.bmp'))


相關文章