Problem with binary image based from a certain pixel's intensity

조회 수: 2 (최근 30일)
Mario
Mario 2015년 3월 11일
댓글: Mario 2015년 3월 12일
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
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
Mario 2015년 3월 11일
I managed to find the solution. It was in the X Y coordinates. The correct code is below:
iV1=1;iV0=0;
roundX=round(Y);
roundY=round(X); %%By switching theese coordinates if fixes the problem that I had in my code.
intensityValue1 = Img1(roundX,roundY);
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
imshow(Img3);
  댓글 수: 2
Image Analyst
Image Analyst 2015년 3월 11일
Images indexes are (row, column), not (x,y). So you should use img1(roundY, roundX), not img(roundX, roundY),
Mario
Mario 2015년 3월 12일
That is correct. I just switched the image indexes instead (row, column). Thanks for clarification.

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

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by