フィルターのクリア

How can I convert grayscale image to a binary image without using a toolbox function?

28 ビュー (過去 30 日間)
maha D
maha D 2016 年 10 月 14 日
コメント済み: DGM 2023 年 8 月 24 日
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?

採用された回答

Image Analyst
Image Analyst 2016 年 10 月 14 日
Just threshold:
binaryImage = grayImage > 0.2; % or < or <= or >= (whatever you want).
No toolbox needed.
  11 件のコメント
Image Analyst
Image Analyst 2023 年 8 月 24 日
Don't use gray as the name of your variable. It is the name of a built-in function. What do you mean by "back"? What happened to it. You still have (the badly named) "gray" in your functions workspace, right? So just use it. You didn't say "clear gray" did you? So it should still be there.
DGM
DGM 2023 年 8 月 24 日
To be clear, let's assume an empty workspace:
inpict = imread('cameraman.tif'); % a uint8-class grayscale image
mask = inpict >= 128; % a logical-class binary image
At this point there are two variables in the workspace: inpict and mask. You can't back-calculate inpict from mask, but you don't have to, since it's still in memory. Just use inpict.

サインインしてコメントする。

その他の回答 (1 件)

Ali nafaa
Ali nafaa 2022 年 11 月 29 日
編集済み: DGM 2023 年 8 月 24 日
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
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by