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.
By
Doug Hull
Doug first used MATLAB in 1994, could not figure it out until he got some help in 1995. He is now dedicated to making sure that no one else wastes a year of their life not knowing MATLAB like he did.
%% 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
Leave a Reply
About
Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.
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