How can I convert grayscale image to a binary image without using a toolbox function?
이전 댓글 표시
I want to create a binary image from a gray scale image, using a specific threshold value of 0.2, but without using im2bw(), which is in the Image Processing Toolbox. How do I do it?
채택된 답변
추가 답변 (1개)
x = imread('cameraman.tif');
figure,imshow(x);
[r,c] = size (x);
output=zeros(r,c);
for i = 1 : r
for j = 1 : c
if x(i,j) > 128
output(i,j)=1;
else
output(i,j)=0;
end
end
end
figure,imshow(output);
댓글 수: 1
DGM
2023년 8월 24일
There's no need for the loops. The appropriate answer was given years prior.
inpict = imread('cameraman.tif'); % a uint8-class grayscale image
mask = inpict >= 128; % a logical-class binary image
... or if inpict is not needed for anything, you can avoid the intermediate result:
mask = imread('cameraman.tif') >= 128; % a logical-class binary image
Display them however you choose.
카테고리
도움말 센터 및 File Exchange에서 Image Data Acquisition에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!