![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246257/image.png)
Selecting specific region around the known indices of a matrix.
4 views (last 30 days)
Show older comments
waqas
on 3 Nov 2019
Commented: Thiago Henrique Gomes Lobato
on 4 Nov 2019
Hi,
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. ![untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246251/untitled.png)
![untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246251/untitled.png)
0 Comments
Accepted Answer
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
figure
subplot(1,3,1)
imshow(A.crack)
title('Original Image')
subplot(1,3,2)
imshow(ADilatated)
title('Dilated Image')
subplot(1,3,3)
imshow(PointsAround)
title('Points in a 3-pixel radius')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246257/image.png)
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
7 Comments
Thiago Henrique Gomes Lobato
on 4 Nov 2019
Not in fspecial as far as I know, but you can achieve a similar effect using a radius 4 and then setting the first row from h to zero, like the example I gave you in the last comment. If I were to convert my example with your notation what I did would be a [3,1].
More Answers (0)
See Also
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!