Replace values to create an image with binary values (0,1)
이전 댓글 표시
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.

채택된 답변
추가 답변 (2개)
Sounds like a logical result would work.
a = [-3.8 -1 0 1 3.8];
c = a~=1
댓글 수: 7
Amjad Iqbal
2022년 2월 21일
Arthur Reis
2022년 2월 21일
You can then convert it to double or int32, for example double( c) or int32( c).
Amjad Iqbal
2022년 2월 21일
Amjad Iqbal
2022년 2월 21일
Cris LaPierre
2022년 2월 21일
Consider sharing your data. You can attach it to your post using the paperclip icon.
Amjad Iqbal
2022년 2월 21일
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;
카테고리
도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


