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

조회 수: 12 (최근 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?
ANKUR KUMAR
ANKUR KUMAR 2021년 7월 11일
Yes, you are correct. I modified the answer for the clarity.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 7월 11일
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