How to display subplot with multiple image with its own x and y axes ?

17 次查看(过去 30 天)
I use subplot to display multiple images ,but it does not show axis for each image in the subplot.How to show it? Here is the code.Hope someone can guide.Thank you.
%create blank image
w = 150;
h = 150;
blankImage= 255*ones(w,h,3,'uint8');
%position of the letter in the empty cell
position_x = (w+1)/2;
position_y = (h+1)/2;
% varying the font size, start from 10 to 16
font_start = 58;
font_end = 64;
num_fontsA = font_start:2:font_end;
% get the number of fonts
numImagesA = length(num_fontsA)
% create a cell array with number of fonts to fill in the image in next step
A = cell(1, numImagesA);
% for loop to create letter 'A'
% grayscale
% store into the cell array
for i=1:numImagesA
for font_size = num_fontsA(i)
img= insertText(blankImage,[position_x position_y],'A','Font','Times New Roman','FontSize',font_size,'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
grayImage= rgb2gray(img);
BWImage = ~grayImage;
background = BWImage == 0;
foreground = ~background;
Newforegnd = foreground;
% figure('Name','Background and Object');
% montage({Newforegnd, background});
% Apply noise on the image
% Apply noise on the alphabet, using 0.01 standard deviation
Newforegndafter = imnoise(img, 'gaussian',0, 0.01);
%Apply noise on the background, using 0.01 standard deviation
backgroundafter = imnoise(img, 'gaussian',0, 0.01);
% imshowpair(background,backgroundafter,'montage');
title("Foreground before and after adding noise");
subplot(2,2,1);
imshow(Newforegnd);
subplot(2,2,2);
imshow(Newforegndafter);
subplot(2,2,3);
title(" background before and after adding noise");
imshow(background);
subplot(2,2,4);
imshow(backgroundafter);

采纳的回答

ANKUR KUMAR
ANKUR KUMAR 2021-7-11
编辑:ANKUR KUMAR 2021-7-11
You need to make xaxis visible in every subplots. Here are the lines which you need to modify.
title("Foreground before and after adding noise");
subplot(2,2,1);
imshow(Newforegnd); h1 = gca; h1.Visible = 'On';
subplot(2,2,2);
imshow(Newforegndafter); h2 = gca; h2.Visible = 'On';
subplot(2,2,3);
title(" background before and after adding noise");
imshow(background); h3 = gca; h3.Visible = 'On';
subplot(2,2,4);
imshow(backgroundafter); h4 = gca; h4.Visible = 'On';
  2 个评论
Tuck Wai Yip
Tuck Wai Yip 2021-7-11
编辑:Tuck Wai Yip 2021-7-11
Sorry for asking this,I am beginner in this, what is difference between xtick and x axis? Wasn't that x axis is the whole scale, but xtick is the 'mark' on the scale? Or it is because the image has no x,y axes when I save it into variable?

请先登录,再进行评论。

更多回答(1 个)

Sulaymon Eshkabilov
subplot(2,2,1);
imshow(Newforegnd);
% Use this command
axis on
...

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by