Astronomy Python - Webb's First Deep Field - Putting Grid Lines

 In Astronomy, putting a grid line (with number blocks) on Image (planets, star field etc.) will simplify the image understanding process.  Each block could be treated as smaller part of the big image and block number could be used as reference number to locate an object.

In the below example, a grid with number block(green in color) is applied to Webb's First Deep Field image.


Image Credits:NASA, ESA, CSA, STScI(without gird)

Below is the python code used.

**********************************************************************

import matplotlib.pyplot as plt

import matplotlib.ticker as plticker

try:

    from PIL import Image

except ImportError:

    import Image


# Open image file

image = Image.open('E:\\astronomy_related\\xy_grid\\webb_first_deep_field_n.png')


# Set up figure

gridLineWidth=100

fig=plt.figure(figsize=(float(image.size[0])/gridLineWidth, float(image.size[1])/gridLineWidth), dpi=gridLineWidth)

axes=fig.add_subplot(111)


# Remove whitespace from around the image

fig.subplots_adjust(left=0,right=1,bottom=0,top=1)


# Set the gridding interval: here we use the major tick interval

gridInterval=100.

location = plticker.MultipleLocator(base=gridInterval)

axes.xaxis.set_major_locator(location)

axes.yaxis.set_major_locator(location)


# Add the grid

axes.grid(which='major', axis='both', linestyle='-', color='green')


# Add the image

axes.imshow(image)


##The below lines can be skipped if labelling of grids is not required

# Find number of gridsquares in x and y direction

nx=abs(int(float(axes.get_xlim()[1]-axes.get_xlim()[0])/float(gridInterval)))

ny=abs(int(float(axes.get_ylim()[1]-axes.get_ylim()[0])/float(gridInterval)))


nx= nx+1

ny=ny+1


# Add some labels to the gridsquares

for j in range(ny):

    y=gridInterval/5+j*gridInterval

    for i in range(nx):

        x=gridInterval/17.+float(i)*gridInterval

        axes.text(x,y,'{:d}'.format(i+j*nx), color='green', fontsize='10',  ha='center', va='center',weight='heavy')

##Can be skipped until here



# Save the figure

fig.savefig('E:\\astronomy_related\\xy_grid\\myImageGrid.png', dpi=gridLineWidth)


*******************************************************************

To know more about  Canny Edge detection please visit below link

https://en.wikipedia.org/wiki/Canny_edge_detector


Credits-

Image Credit

IMAGE: NASA, ESA, CSA, STScI

Webb's First Deep Field (NIRCam Image)

https://webbtelescope.org/contents/media/images/2022/035/01G7DCWB7137MYJ05CSH1Q5Z1Z?Category=03-galaxies&Collection=First%20Images


Code Credit (base code is modified to suit the need)

https://www.codespeedy.com/drawing-grid-lines-on-images-using-python/


Comments

Popular posts from this blog

Astronomy Python - Webb's First Deep Field - Marking the Edges of the Galaxies

Online Observatory for Meteor Scatter Detection - Radio Astronomy.

Astronomy Python - Mars Planet Surface - Creating Sharpen Image from Blur Image