フィルターのクリア

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

34 ビュー (過去 30 日間)
Tuck Wai Yip
Tuck Wai Yip 2021 年 7 月 11 日
編集済み: ANKUR KUMAR 2021 年 7 月 11 日
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 Center および File ExchangeRead, 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