Given a point, locate 3 point in different 8 directions.

1 view (last 30 days)
I'm working with images, and after that I've found a certain pixel, I have to consider 8 directions starting from this point, one direction for each 45 degrees counter-clockwise. On these directions, I have to locate 3 points (the ones for which there is a rapid variation in intensity with the adjacent pixel in that direction).
I really don't know how I can locate these directions and the points that belong to them, so any suggestion and help would be appreciated.
  5 Comments
Francesco Argenziano
Francesco Argenziano on 31 Jul 2020
The square only display the correct points, the original image is just the eye. To find those point, you move along one of the eight directions (starting from the starting point) and for each pair of adjacent pixel on that direction you measure the difference of intensity. The three pixels that have tha maxixum variation are the ones I have to found.
Calculating the variation isn't hard, the biggest problem is how I can move along one direction to calculate that, and how can i find those directions.
J. Alex Lee
J. Alex Lee on 1 Aug 2020
What do you mean "how to find those directions"? Didn't you state that you want it to be every 45degrees? Based on the "target" result, it seems you want to start from horizontal or vertical, so in matlab's coordinates, 0:45:315
"Moving along a direction" and "calculating variations" seems to me to two aspects of one problem: calculating variation along some direction...so what exactly is your difficulty?
Based on how the question is posed, is this some kind of assignment?

Sign in to comment.

Answers (4)

Matt J
Matt J on 1 Aug 2020
Edited: Matt J on 1 Aug 2020
I'm not sure I understand what the how-to challenge is in the question, but the approach that I think you want is to calculate all differences along a specific direction at all pixels simultaneously. That will allow you to efficiently process all differences of a particular type in a highly vectorized manner.
For example, if I call your image A, all southwest to northeast differences can be calculated by,
k=[0 -1;
1, 0];
SWNE=abs(conv2(A,k,'valid')); %southwest to northeast absolute differences
while all north-west to south-east differences can be calculated by
NWSE=abs(conv2(A,flipud(k),'valid'));%northwest to southeast absolute differences
  1 Comment
J. Alex Lee
J. Alex Lee on 1 Aug 2020
Edited: J. Alex Lee on 1 Aug 2020
you could also construct rotated GoG kernels to smooth out any noise; it would also be the more generalizable solution than the kernels specific to 45deg.
alternatively you could probably use gradient components in the principal directions from simpler filters like sobel, and rotate them after the fact (i think)
and then it would still remain to take line scans of the gradient components and identify the "edges".

Sign in to comment.


Matt J
Matt J on 1 Aug 2020
Edited: Matt J on 1 Aug 2020
Or maybe this is what you want. In the code below, A is your image and the result Neighbors(i,j,:) contains all 9 neighbors of A(i,j) including i,j itself. Likewise Differences(i,j,:) will contain all absolute differences of the neighbors.
z=zeros(3);
Neighbors=repmat(A,1,1,9); %pre-allocation
for i=1:9
k=z;
k(i)=1;
Neighbors(:,:,i)=conv2(A,k,'same');
end
Differences=abs(Neighbors-A); %Difference from central pixel

J. Alex Lee
J. Alex Lee on 1 Aug 2020
as long as we're guessing at the problem, an approach that would alleviate the need for line scans would be to rotate the source image itself about the "starting point" and take diff() of the image (or some smoothed version of it)

J. Alex Lee
J. Alex Lee on 1 Aug 2020
Or since there is a built-in called improfile (with one toolbox or another), you can skip the convolutions for gradients, take the profiles of the image itself and just do a 1D diff() on them.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!