# Doug's MATLAB Video Tutorials

## Indexing to make an image in MATLAB

I got a quick question today on how to make a diamond appear on an image in MATLAB. This is really an exercise in indexing and for loops in MATLAB. Let’s see how you can make an image in MATLAB.

### One Response to “Indexing to make an image in MATLAB”

1. Sean de Wolski replied on :

And a few Image Processing approaches:

%% Some info:
% These have the convience of being easy to make multiple diamonds. Simply
% turn any spot you want to have a diamond to be true.

sz = [11 11];
r = 3;

%% Use BWDIST
% Anywhere within the range of our true point will be on.

I = false(sz); %false matrix
I(ceil(sz(1)./2),ceil(sz(2)./2)) = true; %center (or wherever) is true.
D = bwdist(I,’cityblock’)<=r; %true points are equal or closer than r in cityblock distance xform
imagesc(D); %view it

%% Use IMDILATE
% Take our solo point and expand it
%

I = false(sz); %false matrix
I(ceil(sz(1)./2),ceil(sz(2)./2)) = true; %center (or wherever) is true.
D = imdilate(I,strel('diamond',r)); %Dilate with a diamond stucturing element.
imagesc(D); %view it

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 2 + 3 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

These postings are the author's and don't necessarily represent the opinions of MathWorks.