Selecting specific region around the known indices of a matrix.
7 views (last 30 days)
waqas on 3 Nov 2019
I have a path around which I want to select 3 points above and 3 points below to acheive something similar to the picture. Basically I want to select the points that lie within 3 radius points. I have attached the MAT file which includes the indices locations around which I want to select points. It also has the matrix from which the figure can be ploted. Orginal matrix has the same dimensions.
Thiago Henrique Gomes Lobato on 3 Nov 2019
Edited: Thiago Henrique Gomes Lobato on 3 Nov 2019
You can dilate the image with a disk kernel and then take the difference to get the indexes:
A = load('matlab.mat');
h = fspecial('disk',3 ); % Disk element for dilatation
ADilatated = imdilate(A.crack,h); %
PointsAround = ADilatated-A.crack; % Difference to get the new points
IndexAroud = find(PointsAround~=0); % This is the array with the indexes around it
title('Points in a 3-pixel radius')
In case you don't want a disk (radius) but rather a horizontal/vertical line you can just change the kernel, some examples can be founded here https://de.mathworks.com/help/images/ref/imdilate.html