MATLAB Answers

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

4 views (last 30 days)
veenu arora
veenu arora on 18 Aug 2015
Commented: veenu arora on 19 Aug 2015
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

  0 Comments

Sign in to comment.

Answers (2)

Muthu Annamalai
Muthu Annamalai on 18 Aug 2015
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 Comment

veenu arora
veenu arora on 19 Aug 2015
sir i am not getting please elaborate because after doing operations i am getting this kind of image i want proper image.

Sign in to comment.


Walter Roberson
Walter Roberson on 18 Aug 2015
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 Comment

veenu arora
veenu arora on 19 Aug 2015
sir after recombining i am not getting the proper image..plz suggest me how i could get the proper image after recombining

Sign in to comment.


Translated by