How to save an image without reverse the black/white in the image ??

1 view (last 30 days)
I want to extract the color region from image , this works fine but the problem is in the save part . When I save the image , it converts the black to white and vise versa but I do not know why . This is the image :
and this is how it saves it :
matlab code:
I = imread('./img/bfly.png');
[Iu,ia,iu] = unique(reshape(I,[],3),'rows');
counts = accumarray(iu,1);
[counts,sortinds] = sort(counts,'descend');
N = 10;
largestLabels = sortinds(1:N);
for i= 1:6
mapi = reshape(iu == largestLabels(i),size(I,1),size(I,2));
L = bwlabel(mapi);
figure,imshow(L ==0)
im_name=strcat('image',num2str(i),'.png');
imwrite(mapi,im_name)
end

Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!