MATLAB:: Drawing a number on a image (Matrix) on MATLAB

TripleS picture TripleS · Dec 7, 2011 · Viewed 9.4k times · Source

I'm using matlab in order to perform modifications on an image. I have loaded an image on Matlab. (the image may be in different resolutions) Converted the image to gray scale then converted the image's matrix to double.

I have drawn grid lines on the image (I have posted the code how to do that somewhere here on stack over flow).

My problem is that I may have upon the 1000 squares as a result from girding the image on the X axis and the Y axis.

I'd like to numbering the squares in that image.

Is there an option of drawing numbers on Matlab ? I'd be glad to receive any information about that (except from being a clicking monkey and writing 0 till 1000 on paint haha... ).

Cheers S

Answer

yuk picture yuk · Dec 7, 2011

Here is a code example to put text labels on an image in the middle of grids:

x = imread('cameraman.tif');
image(x)
axis image
grid on
%# grid domains
xg = 0:50:200;
yg = 0:50:200;
%# label coordinates
[xlbl, ylbl] = meshgrid(xg+25, yg+25);
%# create cell arrays of number labels
lbl = strtrim(cellstr(num2str((1:numel(xlbl))')));
text(xlbl(:), ylbl(:), lbl(:),'color','w',...
    'HorizontalAlignment','center','VerticalAlignment','middle');

enter image description here