필터 지우기
필터 지우기

Unable to perform assignment because the size of the left side is 20-by-1 and the size of the right side is 20-by-20-by-3.

조회 수: 1 (최근 30일)
Hi, I need to make image with single letter. It needs to vary in terms of font size and noise using variance(later on) under the same parameter for image size. I should store the images withdifferent font sizes of the letter and display it. Please help. I have try to store it in cell array. But it said "
How could I solve this? I tried to use cell array but I failed. Thank you. I am quite confused with the array, Hope to have someone to guide me. Thank you.
%create blank image
w = 20;
h = 20;
blankImage= 255*ones(w,h,3,'uint8');
position_x = (w+1)/2;
position_y = (h+1)/2;
% % Extract the individual red, green, and blue color channels.
% redChannel = rgbImage(:, :, 1);
% greenChannel = rgbImage(:, :, 2);
% blueChannel = rgbImage(:, :, 3);
font_size = 10;
new_font = font_size + i;
font_start = 10;
font_end = 16;
total_img = font_start:2:font_end;
length(total_img)
% size_A = zeros(8, 'int8');
%function row_column =
% size_A = cell(1,pic_num);
%
for i=1:length(total_img)
for font_size = total_img(i)
A(:,:,i)= insertText(blankImage,[position_x position_y],'A','Font','Times New Roman','FontSize',font_size,'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
A(:,:,i)= rgb2gray(A(:,:,i));
A(:,:,i)= imnoise(A(:,:,i), 'gaussian', 0.01);
i = i+1;
end
end
% subplot(2,2,1);
montage(A);
% imshow(A(i+1);
axis on;
title('A uppercase with noise');

채택된 답변

DGM
DGM 2021년 5월 1일
I don't have CVT, so I can't test this, but insertText() is returning an RGB array and you're trying to fit it into a single page of a multipage image. If you're doing operations with a working image that doesn't start out with the right dimensions to fit in its destination, don't try to put it there until it does fit.
thispage = insertText(blankImage,[position_x position_y],'A','Font','Times New Roman','FontSize',font_size,'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
thispage = rgb2gray(thispage);
A(:,:,i) = imnoise(thispage, 'gaussian', 0.01);
  댓글 수: 5
Image Analyst
Image Analyst 2021년 5월 1일
If @DGM's answer solved your problem, please click the "Accept this answer" link to give him reputation points.
Tuck Wai Yip
Tuck Wai Yip 2021년 5월 2일
편집: Tuck Wai Yip 2021년 5월 2일
Hi,@Image Analyst I clicked "Accept this answer" before you said it :).By the way, thank you on your reminder.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by