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

조회 수: 4 (최근 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;

답변 (1개)

Athul Prakash
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!

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by