How to binarize an image by keeping the NaNs and using a threshold?

조회 수: 5 (최근 30일)
Hello,
I am a novice with Matlab. I have a 3D array with NaNs, corresponding to the outside of an porous object. I would like binarize this image (units 8) with a treshold equal to 15. To do it, I used:
Bimg = imgd3 >15;
The binarization works but when I do it, the NaNs become 0 value. I want to keep the NaNs because they correspond to the outside of my object.
Any idea ?
Thank :)

채택된 답변

Matt J
Matt J 2019년 1월 28일
nanmap=isnan(imgd3);
Bimg = imgd3 >15;
Bimg(nanmap)=nan;
  댓글 수: 2
Lequette Kevin
Lequette Kevin 2019년 1월 29일
편집: Lequette Kevin 2019년 1월 29일
Thank Matt J for your answer. However, when I used this code, there is a error message:
NaN's cannot be converted to logicals.
But if I do this:
nanmap=isnan(imgd3);
Bimg = double(imgd3 >15);
Bimg(nanmap)=nan;
It works ^^ Thank for your help!
Walter Roberson
Walter Roberson 2019년 1월 29일
By definition, binary only has 2 values, not three. Not 0, 1, or nan.
You should be storing your mask in a different array.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by