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

18 vues (au cours des 30 derniers jours)
Tuck Wai Yip
Tuck Wai Yip le 11 Juil 2021
Modifié(e) : ANKUR KUMAR le 11 Juil 2021
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);

Réponse acceptée

ANKUR KUMAR
ANKUR KUMAR le 11 Juil 2021
Modifié(e) : ANKUR KUMAR le 11 Juil 2021
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 commentaires
Tuck Wai Yip
Tuck Wai Yip le 11 Juil 2021
Modifié(e) : Tuck Wai Yip le 11 Juil 2021
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?
ANKUR KUMAR
ANKUR KUMAR le 11 Juil 2021
Yes, you are correct. I modified the answer for the clarity.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by