I have created a program to find centroids of peaks in a low noise image with small circular peaks evenly spaced in 11 rows and some number of columns. The peaks generally stay in line of some grid.
The images come from a streak camera that changes voltages between two parallel plates to allow us to see images as they change in time over durations such as 3ns or 18 ns. The separation of the peaks in x (dx) is the same across all images with a sweepspeed of 3ns ect. dy is always the same.
(poor example below)
| * * * * * |
| * * * * * |
| * * * * * |
Basically I find the peaks with the following code
stats = regionprops(threshimg,smoothimg, 'Area', 'WeightedCentroid');
I make a threshold and use regionprops to calculate the weighted centroid and areas of each region and eliminate the centroids below a certain area. Usually picking a threshold and minarea grabs unwanted peaks that are from scattering or noise or leaves out points that I want. In order to get the current points I make sure to pick a threshold and minarea to get all the desired points with minimal unwanted points and use the brushtool to selectively delete the bad ones. I will then save the remaining centroids to a new variable and use it for my analysis. I would really like to figure out a way to automate this process.
I will somehow allow the user to click on the center peak in the image and to the peak over and up 1. (this gives me an aproximate distance between peaks in x and y called dx and dy) currently using information specifically for the image I am testing the automation on for dx and dy. I create a grid using this information such that each square should contain one peak. Eg I made a chessboard and close to the center of each square will be a peak. From here I isolate each region and run my peakfinding program in an attempt to automatically find 1 peak.
_Automatically Finding 1 peak_
After making the grid I apply my program to the region to find one peak. This is where I start having dificulty.
Since I am testing on an image I am familiar with, I have a general idea for starting threshold and minarea. I would like to do something that can automatically get a ballpark idea for the starting threshold. I'm guessing something with histograms would work. I looked at some thresholding techniques but for the most part they don't apply to data with low background and high peak values. (depending on my sweepspeed the low to high can be very high with slower speeds being higher and faster being lower. )
In my test I start with some set value and have created a crappy algorithim to change the threshold and minarea and check for 1 peak. Essentially I start with some ratio between threshold and minarea and increase one, check increase the other, check increase the other...ect If it doesn't find it after some amount of tries it changes the ratio and resets. This is a very inefficient and ineffective system but I haven't really come up with anything else.
Another issue is that when my program ends up finding the 1 centroid in the region, I want to be sure that it is the correct one, I was thinking about fitting a gaussian to my peaks and somehow comparing them to others to decide if they are the correct peaks.
_Questions summed up_
1. I used a pretty arbitrary smoothing function does anyone know if there is anything better to try?
2. Does anyone have advise for allowing a user to click on a plot and grab the location in a variable? I've been looking at interactivity tutorials and have had difficulty?
3. I suspect that a lot of you guys do stuff like this a lot. Is my approach effective or is there a better way to do it? I strongly suspect there is.
4. How can I get a starting idea for what threshold to use automatically?
5. Is there a better way to change the threshold and minarea compared to the way I am currently doing it? I think my algorithim for that is absolutely horrible.
6. Does anyone have some examples they could direct me to if there is something similar to this?
Thanks a lot! I decided to be very detailed since I think I'd have trouble phrasing the problem in single questions with no context. Let me know if you want me to share code or data.