Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the Original version of the page.

Indexing to make an image in MATLAB 1

Posted by Doug Hull,

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.

1 CommentsOldest to Newest

Sean de Wolski replied on : 1 of 1
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