As for shots with other things in them such as the Star Destroyer or planets, there are two ways around it.
1) Rotoscope the shot to mask out the objects you don't want in the process (i.e. mask out the destroyer and the planet)
2) Refine your code so that it only works on the stars, basically a discovery pass where you looks for objects less than xx pixels in size that are surrounded by 'black' and then only run your processing on said objects. This method means no tedious rotoscoping, but more testing to ensure you are only processing the part of the image you are interested in. One way to check is to flag all objects processed in bright red or similar, so you can see hwat your code is working on and tweak it til it is correct.