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!