MATLAB Answers

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

조회 수: 11(최근 30일)
veenu arora
veenu arora 18 Aug 2015
댓글: veenu arora 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...
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);
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;
for c = 1 : size(ca, 2)
for r = 1 : size(ca, 1)
fprintf('c=%d, r=%d\n', c, r);
Text = sprintf('M');
H = vision.TextInserter(Text);
H.Color = [0.0 0.0 0];
H.FontSize = 3;
b = step(H,ca{r,c});
% imshow(b);
c1(8*(c-1)+1:8*c,8*(r-1)+1:8*r,:) = b;
plotIndex = plotIndex + 1;
if true
% code
% gh= imagerestore(a); if true
% code

  댓글 수: 0

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


Muthu Annamalai
Muthu Annamalai 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.

  댓글 수: 1

veenu arora
veenu arora 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.

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

Walter Roberson
Walter Roberson 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

veenu arora
veenu arora 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

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

Community Treasure Hunt

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

Start Hunting!

Translated by