MATLAB: How to make shape display in black colour and background in white colour

digital image processing

This is my code below
subplot(1,3,1); % subplot(m,n,p) m and n define the array of all the images together, and p defines the position of this particular plot in that array
%as an example subplot(1,3,1) says that there is 1 row of plots, 3 columns
%and the following plot should be placed in position 1
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY); % Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
circlePixels = (rowsInImage – centerY).^2 … + (columnsInImage – centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
axis equal; %makes circle look like a circle by giving axis equal distribution
axis off; %hide the axis
subplot(1,3,2);
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY); % Next create the circle in the image.
xCenter = 12;
yCenter = 10;
% Modification to the FAQ is the next two lines.
numSides = 7; % <=== CHANGE THIS NUMBER
theta = linspace(0, 2*pi, numSides);
radius = 8;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
axis equal; %makes circle look like a circle by giving axis equal distribution
axis off;
axis equal; %makes circle look like a circle by giving axis equal distribution
axis off; %hide the axis
subplot(1,3,3);
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
circlePixels = (rowsInImage – centerY).^2 … + (columnsInImage – centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
axis equal; %makes circle look like a circle by giving axis equal distribution
axis off; %hide the axis

Best Answer

Just do
image(~circlePixels);
Or else change your colormap
colormap([1, 1, 1; 0, 0, 0]);