MATLAB Answers

How can i change places to pixel values(black ones to white, white ones to black) of binary image?

1 view (last 30 days)
Zuy
Zuy on 24 Apr 2020
Commented: Zuy on 2 May 2020
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 Comments

Sign in to comment.

Answers (1)

Athul Prakash
Athul Prakash on 30 Apr 2020
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!

Community Treasure Hunt

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

Start Hunting!

Translated by