DIP Project Report
DIP Project Report
Table of Contents
Obs. No. TITLE PAGE NO.
1 INTRODUCTION 3
2 BACKGROUND 3
3 THEORY 4
4 COMPUTATIONAL WORK 5
6 APPLICATIONS 11
7 CONCLUSION 11
8 REFERENCES 12
9 ACKNOWLEDGEMENT 12
Introduction
Have you ever counted the number of stars in the night sky? Are they in Hundreds? Thousands?
Lakhs? Searching for it everywhere on google would be lame, hence we bought a new method of
counting the stars in the Night Sky. Astronomers have spent a lot of time cataloging with
telescopes and a piece of paper. This method which we used is none other than coding with the
help of a Digital Image.
The main aim of our project is to count the number of stars in the provided image. We did this
with the help of image thresholding. The thresholding methods replace each pixel in an image
with a black pixel if the image intensity Ii,j is less than some fixed constant T (that is, Ii,j < T), or
a white pixel if the image intensity is greater than that constant C.
Heavy, bright stars are found quite rarely in space whereas Small, dim stars seem to be the most
common stars in space, at least locally, but can only be seen with large telescopes, and then only
when they are within a few tens of light-years from Earth. Similar concept being used here in this
code that the bright stars are found rarely but are included and the dim stars are found commonly
in space in the provided image. So let's get going to explore this project of counting the number
of stars in the night sky using an image
Background
Star counts are bookkeeping surveys of stars as well as the statistical and geometrical methods
used to correct the survey data for bias. The surveys are most often made of nearby stars in the
Milky Way Galaxy. One of the interests of astronomy is to determine how many stars there are of
each of several types that stars can be categorized into, and how these stars are distributed in
space.When performing star counts, astronomers consider many different categories that have
been created to classify a few stars that have been well studied. One of the hopes of studying the
results of star counts is to discover new categories. Different counts typically seek to categorize
stars for only a few of the qualities listed below, and determine how common each considered
quality is and how stars of that kind are distributed.There are many unavoidable problems in
counting stars for the purpose of getting an accurate picture of the distribution of stars in space.
The effects of our point of view in the galaxy, the obscuring clouds of gas and dust in the galaxy,
and especially the extreme range of inherent brightness, create a biased view of stars.
Theory
Image Processing is a very diverse and developing field which is used in various applications
nowadays, from Rocket science to even making our selfies look better, detecting fingerprints and
solving a lot of other problems in different industries. Here, as we mentioned, we are going to
discuss its application in the process of counting the number of stars in a given satellite image.
The idea is to filter out some specific regions of the image wherein we try to detect the stars. The
process of detection is carried out by simply identifying the pixels of the stars which are not the
same as the background of the image. Essentially, it involves the stars which are bright, so they
would be corresponding to the higher values of the intensity, and the background, being dark,
would correspond to the lower values of the intensity.
There would be various stars, each of which would take up a different amount/number of pixels
in the image. So, each star could amount to more than one pixel, and all of those pixels which
amount to one star would give a count of 1 every time the kernel is run through the whole image
and it detects such a group of pixels, which are different from the background pixels. Thus, on
each detection of a variant pixel group, the count keeps rising and finally we will get a total
count of the stars in a particular image. This can be tried out for an image with a known value of
the stars, and then after multiple readings, and calibration of the code, we can test it to find an
unknown count of stars in a given image.
Other than the method which was used by us in this project, there is a more conventional or
standard method used in general for the detection of stars in a given image, which is known as
the Blob Detection method. A Blob is a group of connected pixels in an image that share some
common property. The basic idea of Blob detection also involves Image Thresholding, followed
by grouping the connected pixels together. Further, the blobs which are very close compared to a
threshold distance are merged together. In this technique various filters are also applied which
make the computation a little bit more advanced, but more precise as compared to other methods,
as here we can filter out the specific types of blobs that we want to detect.
Computational Work
Flowchart
Algorithm
● Import the required libraries
● Using the imported libraries import the image
● Convert the colored image into grayscale image
● Thresholding
○ Select a specific range of intensity for the stars
○ Make a for loop
○ Map all the selected intensity level to the highest intensity level
○ Map all the pixel to zero which are out of the selected intensity range
● Check the dimensions of the image
● Set count to zero
● Make a for loop
○ read the individual pixel value
○ Neglect all the pixels with zero intensity
○ If a white pixel is detected then consider the coordinate of that pixel as p
and q
○ Increase the count by one
○ Set pixel (p,q) to (p+3,q) as zero
○ Similarly set (p-1,q+1) to (p+3,q+1)) , (p-1,q+2) to (p+3,q+2), (p-1,q+3)
to (p+3,q+3) as zero
● Print the total count
● Repeat the same procedure for an flipped image
● Print the total count
● Take average of both the counts
Colab link
https://colab.research.google.com/drive/1L0_ZNNlzBvRrwfmu7gwXomYV4P
_hSILR?usp=sharing
CODE
cv2_imshow(Starimage)
x,y = np.shape(grayscaled_star_image)
binary_image= np.zeros((x,y))
for p in range(x):
for q in range(y):
if (grayscaled_star_image [p][q]<100):
binary_image[p][q]=0
else:
binary_image[p][q]=255
s=binary_image
count=0
for p in range(xsize):
for q in range(ysize):
if s[p][q]==255:
count = count+1
s[p][q]=0
if p==853 or q==1280:
s[p][q]=0
s[p][q]=0
s[p][q]=0
s[p][q]=0
s[p][q]=0
#creating window of 4x5 on which the pixel s[p][q] will occupy the
coordinates (2,1) and the setting all the pixel in that window to zero
else:
s[p+1][q]=0
s[p+2][q]=0
# s[p+3][q]=0
# s[p+4][q]=0
s[p][q+1]=0
s[p-1][q+1]=0
s[p+1][q+1]=0
s[p+2][q+1]=0
# s[p+3][q+1]=0
# s[p+4][q+1]=0
s[p][q+2]=0
s[p-1][q+2]=0
s[p+1][q+2]=0
s[p+2][q+2]=0
# s[p+3][q+2]=0
# s[p+4][q+2]=0
s[p][q+3]=0
s[p-1][q+3]=0
s[p+1][q+3]=0
s[p+2][q+3]=0
# s[p+3][q+3]=0
# s[p+4][q+3]=0
s[p][q+4]=0
s[p-1][q+4]=0
s[p+1][q+4]=0
s[p+2][q+4]=0
# s[p+3][q+4]=0
# s[p+4][q+4]=0
print(count)
#cv2_imshow(s)
Results and Discussion
The image from which the count of stars was to be extracted is provided as image 1.
The central region of this image is very bright and the image seems to contain some noise and
hence a threshold of 100 was fixed. So pixels below 100 intensity values are neglected as this
intensity range produces the most clear image.
The binary image that was obtained is provided as image 2.
Three different mask size are used to find the star count and the star count by each window is as
follows:
3x3 window = 1093 stars
4x4 window = 1076 stars
5x5 window = 1058 stars
Even after changing the window size from 3x3 to 5x5 the count remains consistent which shows
that the obtained star count is closer to the actual star count. Another advantage of this method
is that even if we increase the window size and suppose the two stars comes under the same
window and even if a single pixel of the second star is out of that window then that pixel would
be counted as the second star.
Image 1
Image 2
Applications
3) Image Retrieval.
4) Medical Imaging.
Conclusion
Our main motive was to count the number of stars in the sky and we did it. There's much more
data present in the technique of counting stars. We used the basic libraries for coding an image
and then worked on the image thresholding. A suitable range of intensity is required in order to
map all the selected intensity levels to the maximum intensity due to which bright stars appear to
be in the visible range and the minor stars and noise in the image vanish.
We dealt with individual pixels in the project, so basically whenever a bright pixel is detected the
neighbouring region which has the other pixels of that star are mapped to zero and then goes on
further and keeps detecting the bright stars. As soon as a star gets detected, the bright pixel gets
detected too and hence after the detection, the entire star gets mapped to zero. So as to get an
accurate solution, 3 different window sizes were used and all the three window sizes produce the
result in the same range from which we can infer that the count of stars that are obtained are
pretty much accurate. Hence, we can say that counting stars is not an easy task, but a wonderful
opportunity to perform such an incredible topic.
References
1. https://v4.software-carpentry.org/media/stars.html
2. https://www.analyticsvidhya.com/blog/2019/02/building-crowd-counting-model-python/
3. https://en.wikipedia.org/wiki/Star_count
4. https://physicspython.wordpress.com/2021/02/23/counting-stars-with-python-and-pandas
/
5. https://www.linkedin.com/pulse/image-processing-using-python-satyajit-singh
6. https://en.wikipedia.org/wiki/Crowd_counting
Acknowledgement
We would genuinely like to thank the Department of Physics for organising this DIP
course which helped us in succession of this amazing project. We are also thankful to Prof.
Rohan as he was the one who guided us with this project and gave us hopes of doing it, without
him, we would be at a loss.