MATLAB Answers


Generating a grid around circles in an image

Asked by Andrew Luce on 2 Aug 2019
Latest activity Commented on by Andrew Luce on 2 Aug 2019
I have created a costas array on matlab. Say I recreate this array on paper and take a picture of it. I want to detect if it is a costas array. Is there an way to make an interactive grid that I can drag over the image and detect if there is a black dot within each cell of the grid?

  1 Comment

You could load the image onto an axis. Then using image processing tools to get the coordinates of each black point. Once you decide on the width and height of your grid squares, you could merely +/- 1/2 of those dimentions from each data point so that each coordinate becomes a range in the x and y directions. Then determine if any ranges overlap. That doesn't fulfill all of the requirements of a Costas Array but it should get you started.

Sign in to comment.


1 Answer

Answer by David K.
on 2 Aug 2019
 Accepted Answer

So I felt like making it interactive so I used the built in guide function in matlab to create a GUI. Attached are the two files. Basically it lets you type in the x and y intervals for your grid. Then upon clicking update it will show the grid lines, put a red star at the center of each grid box that it believes the black dot is in and then will do a basic check for costas array.
Inside the m file is a lot of stuff that makes the gui work. You don't need most of it but I put a big stuff happens here comment to help find the main things. There is a function called testCostaArray where I do the test to see if any of the points are in the same column or horizontal. I think it should be set up well enough to let you check for the other conditions that make something a costas array since I did not put those in.
Godd luck, hope this helps.


+1; neat!
Don't forget to download the image in the question and name it "costas dots.jpeg".
[update] but I have some questions....
1) Does a Costas array requires that all columns / rows contain 1 dot or is the requirement merely that each column and row has no more than 1 dot (and allows for 0 dots)? If the prior is true, this solution does not work because when I set the grid parameters to [20,20], there are lots of columns/rows without dots but the feedback reports that the test passed.
2) Does your code also fulfil the 2nd requirement that all of the n(n − 1)/2 displacement vectors between each pair of dots are distinct?
Lastly, it would be more interpretable if the axes had tick marks so we could eyeball the coordinates of the grid lines.
Oops, meant to mention the image requirement in my answer.
I do not actually know much about costas arrays so I was mainly focusing on the interactive part and determining where each dot is.
I am only checking that there are no repeat dots in each row or column since that is an easy condition. I did not know that (1) might be a condition, and I left (2) to be filled in by the questioner. I set it aside as a function in hopes that it would be a good enough framework to add the changes to the determination logic. If you want to add those condition in, go for it!
This is great, the only thing that I would ahve to say is that it would be nice if you can anchor one of the dots so you wouldn't spend so much time looking for where the dots line up

Sign in to comment.