
Replace values to create an image with binary values (0,1)
5 ビュー (過去 30 日間)
表示 古いコメント
Dear Researchers,
I have a matrix (2D image) which I need to replace values in such a way to obtain binary image.
I used Max function which replace values for one condition. However, In this case, I need to replace values greater and less than zero with zero (0) and replace all values = zero with 1.
I have uploaded image, vaues are ranging from (-3.8 to 3.8), can you please guide me on how to obtain binary image.
Many thanks in advance.

0 件のコメント
採用された回答
Image Analyst
2022 年 2 月 21 日
OK, now that you've added the .mat file, there are no values that are exactly 0. You need to define a range.
s = load('image.mat')
V = s.V;
subplot(2, 2, 1);
imshow(V, []);
colorbar
subplot(2, 2, 3:4);
histogram(V, 256);
grid on;
title('Histogram of V')
xlabel('Value')
ylabel('Count')
% There are no values that are exactly zero so let's pick a tolerance
tolerance = 0.1;
binaryImage = abs(V) < tolerance;
subplot(2, 2, 2);
imshow(binaryImage, []);

その他の回答 (2 件)
Cris LaPierre
2022 年 2 月 21 日
Sounds like a logical result would work.
a = [-3.8 -1 0 1 3.8];
c = a~=1
7 件のコメント
Cris LaPierre
2022 年 2 月 21 日
The challenge I see is that none of your data values exactly equal 1. You'll need to look at your data and decide what range of values you want to consider to represent land.
Image Analyst
2022 年 2 月 21 日
" I need to replace values greater and less than zero with zero (0) and replace all values = zero with 1. "
So why don't you just do
outputMatrix = inputMatrix == 0;
0 件のコメント
参考
カテゴリ
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!