Problem with binary image based from a certain pixel's intensity
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have a problem regarding getting my pixel's intensity.
I have a binary image as a result of my segmentation algorithm (region growing) and I get a binary image (Img1). But, the problem is that sometimes I get inverted binary image (black becomes white and viceversa). In order to overcome this problem I wrote a little code where I want to overcome this since I want that my segmented object in binary image always be white(1) and background black(0):
Img1 - this is my binary image from my segmentation algorithm
iV1=1;iV0=0; % I used this later on
roundX=round(X); %%X and Y are my pixels coordinate (one pixel)
roundY=round(Y); %%with round I wanted to round up the coordinates number, so that they do not have any decimals
intensityValue1 = ~Img1(roundX,roundY); %& so I used this to get it's intensity value (1 or 0). But first problem that ocured in that I do not get the right intensity value from that pixels coordinates so I used '~' to correct that. Is that ok?
My output binary image displays either white objects (1) and black background (0) (like I wanted), or black object and white background (which I do not want). How can I bypass this problem with if, else if or then functions in order to always get binary image with white objects and black background?
I tried but I could not get the desired results. Here is my code that I wrote by I'm not getting what I want:
if intensityValue1==iV0;
Img2=imfill(Img1,'holes');
else Img2=imcomplement(Img1);
end
figure,imshow(Img2);
intensityValue2 = ~Img2(roundX,roundY);
if intensityValue2==iV0;
Img3=imcomplement(Img2);
else Img3=(Img2);
end
figure,imshow(Img3);
Is there maybe a more simple solution?
Thanks in advance!
댓글 수: 1
Image Analyst
2015년 3월 11일
Upload the original binary image. Then upload the one that you would like to have. If you think it will help, upload the original rgb or gray scale image and your region growing code.
답변 (1개)
Mario
2015년 3월 11일
댓글 수: 2
Image Analyst
2015년 3월 11일
Images indexes are (row, column), not (x,y). So you should use img1(roundY, roundX), not img(roundX, roundY),
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!