MATLAB: Image analysis – Astronomical .FITS file – streak/line detection

astronomyedge detectionfitshoughimage analysisImage Processing Toolboxline detectionstarstreak detection

I am attempting to write code to analyse .FITS images.
My goal is to find those images that contain moving objects (asteroids), which appear as streaks (lines). I would like to reject images that contain just stars (points of light).
There is a rather large variance in image background, and streak size, that I am dealing with.
I am very new to coding, so would appreciate any suggestions to achieve my goal. After reading through examples and documentation online, I have tried thresholding using 'graythresh', then 'bwmorph' processes before the 'houghpeaks' process to detect lines.
I am not committed to any one way of line detection – any suggestions whatsoever are welcome and much appreciated!
Many thanks in advance.

Best Answer

Threshold the image and run regionprops. Then look for blobs that have an area more than usual. Like maybe stars have an area of 5 but streaks have an area more than 10 or something. Get a histogram of areas for a few images with streaks and see what their areas are.
binaryImage = grayImage > threshold;
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Area');
allAreas = [props.Area];
histogram(allAreas); % Display distribution
grid on;
biggestStarArea = 15; % Whatever works.
if max(allAreas > biggestStarArea)
msgbox('Image has a streak!');
else
msgbox('Image has has no streaks.');
end