How can i change places to pixel values(black ones to white, white ones to black) of binary image?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
How can i change black pixels to white and white pixels to black of my image?
I am trying this code but i get an error
I = imread('Deneme_10.png');
Igray=rgb2gray(I);
BW=imbinarize(Igray);
BW2 = imfill(BW,'holes');
BW3 = bwareaopen(BW2,8000);
BW3(BW3==0)=1 && BW3(BW3==1)=0;
0 个评论
回答(1 个)
Athul Prakash
2020-4-30
Hey Zuy,
I don't think you can concatenate statements in matlab using '&&' - that is a logical operator, the kind that is used mostly within an if condition. I presume that the error you are receiving is related to that; please try to post the actual error message when you ask a question on the community so that we can understand your problem better. This should increase your chances of getting a response manifold, in my experience.
Here's a solution you can try out:
You need to use a copy of the image before changing colors, otherwise you'll be overwriting the first change when you make the second one, and produce all 0's (or all 1's).
% 'I' hold the binarized image.
temp = I;
I(temp==1)=0;
I(temp==0)=1;
Hope it Helps!
2 个评论
Athul Prakash
2020-4-30
Alternatively, you may use the imcomplement function. Please read the doc below:
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!