how can i combine 8*8 blocks into image after inserting text in each block?

1 次查看(过去 30 天)
i have an image and i divite it into 8*8 blocks afterthat i have inserted text in each block,now i have to recombine these blocks to form proper image..plz suggest me the code...
clc;
clear all;
close all;
fontSize = 20;
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'lena.png';
fullFileName = fullfile(folder, baseFileName);
%fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
figure,imshow ('lena.png');
a = imread(fullFileName);
a = imresize(a, [64 64]);
[rows columns numberOfColorBands] = size(a);
ca = mat2cell(a,8*ones(1,size(a,1)/8),8*ones(1,size(a,2)/8),3);
plotIndex = 1;
c1=zeros(size(a,1),size(a,2),3);
for c = 1 : size(ca, 2)
for r = 1 : size(ca, 1)
fprintf('c=%d, r=%d\n', c, r);
%subplot(8,8,plotIndex);
Text = sprintf('M');
H = vision.TextInserter(Text);
H.Color = [0.0 0.0 0];
H.FontSize = 3;
b = step(H,ca{r,c});
size(b);
% imshow(b);
c1(8*(c-1)+1:8*c,8*(r-1)+1:8*r,:) = b;
plotIndex = plotIndex + 1;
end
end
size(c1)
imshow(uint8(c1))
if true
% code
end
% gh= imagerestore(a); if true
% code
end

回答(2 个)

Muthu Annamalai
Muthu Annamalai 2015-8-18
You have code that almost works, pending a linear transformation; I would suggest trying the 2-step recipe,
  1. Build the mosaic image and record the co-ordinates for text() command in gobal reference axis as oppose to the local reference axis.
  2. Once all 8x8 mosaics are layed out on the figure, start adding text() command data at the (x,y) global positions you had recorded.
HTH
  1 个评论
veenu arora
veenu arora 2015-8-19
sir i am not getting please elaborate because after doing operations i am getting this kind of image i want proper image.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2015-8-18
Have you considered using blockproc() instead the looping over mat2cell() ?
Also you would normally create your vision.TextInserter object before your loop and call it once on each block.
  1 个评论
veenu arora
veenu arora 2015-8-19
sir after recombining i am not getting the proper image..plz suggest me how i could get the proper image after recombining

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by