Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Assignment one cs 519, Assignments of Computer Science

assignment 1 for scientific visualization

Typology: Assignments

2024/2025

Uploaded on 06/17/2025

ceci-john
ceci-john 🇺🇸

2 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5

Partial preview of the text

Download Assignment one cs 519 and more Assignments Computer Science in PDF only on Docsity!

HW'11.1. Images of Mars In this question, we will apply a colormap to a grayscale image in an attempt to identify features on the surface of the planet Mars. The image below is a digital elevation model (DEM) based on data from the Mars Orbiter Laser Altimeter, an instrument on NASA's Mars Global Surveyor. The full DEM represents more than 600 million measurements gathered between 1999 and 2001 and converted to elevations above the areoid as determined from a Martian gravity field solution. The image here is a reduced resolution version of the full DEM, in which each pixel represented 463 square meters. In the original elevations ranged from -8200 meters below the areoid to 21229 meters above. In the image here, the elevation data at each pixel is normalized to fall in the range [o, 1. You will need to write Python code to complete the following tasks: 1. Convert the numpy array mars_gray to a luminance image Lum_img. Currently mars_gray has RGB values per-pixel and each color channel has the same value. Use array slicing to create a numpy array with a single value per-pixel. You can find an example of this in the matplotlib image tutorial. 2. Create a LinearSegmentedColormap named mars_colormap with the following transfer functions: Red: anchor | Yytefe | Yright 0.0} 0.0 0.0 0.2] 0.0] 0.14 0.75 | 1.0 1.0 1.0] 0.7 0.7 Green: anchor | Ytefe | Yright 0.0} 0.0} 0.14 0.24 | 0.14] 0.24 0.3} 07} 0.7 0.4} 03] 0.0 1.0] 0.0 0.0 Blue: anchor | Yteft | Yright 0.0} 10} 1.0 0.28 | 0.0} 0.0 1.0] 0.0] 0.0 You can consult the matplotlib colormap tutorial for information on how to do this. 3. Apply your colormap to the luminance image and generate a numpy array with pseudo-color values...you can do this with mars_red = mars_colormap( lum_img) When you plot the resulting pseudo-coloring, you should be able to see what could have been an ancient ocean shown in blue: user_code.py | & | 1 import numpy as np 2 import matplotlib.pyplot as plt 3 import matplotlib.image as mpimg 4 from matplotlib import cm 5 from matplotlib.colors import ListedColormap, LinearSegmentedColormap 6 7 # Create the custom LinearSegmentedColormap (mars_coLormap) 8 # Red channel transfer functions 9~ red_channel = [ 10 (0.0, 0.0, 0.0), 11 (@.2, 0.0, 0.14), 12 (0.75, 1.0, 1.0), 13 (1.0, 0.7, 0.7), 14] 15 16 # Green channel transfer functions 17+ green_channel = [ 18 (0.0, 0.0, 0.14), 19 (0.24, 0.14, 0.24), 20 (0.3, 0.7, 0.7), 21 (0.4, 0.3, 0.0), 22 (1.0, 0.0, 0.0), 23] 24 25 # Blue channel transfer functions 26~ blue_channel = [ 27 (@.0, 1.0, 1.0), 28 (0.28, 0.0, 0.0), 29 (1.0, 0.0, 0.0), 30] 31 32 # Create the LinearSegmentedColormap 33+ cdict = { 34 "red': red_channel, 35 "green': green_channel, 36 "blue': blue_channel, a7 iy 38 39 mars_colormap = LinearSegmentedColormap("mars_colormap", segmentdata=cdict, N=256) 41 # Load the grayscale image with RGB channels 42 mars_gray = mpimg.imread('mars.png') 44 # Convert to a single-channel Luminance image 45 lum_img = mars_gray[:, :, @] # We assume the RGB channels are identical, using any channel for Luminance 47 48 49 5@ cel Be) # Apply the colormap to the luminance image mars_red = mars_colormap(lum_img) # Generate pseudo-color image # Display the pseudo-color image plt.imshow(mars_red) # Display the pseudo-color image with the custom colormap applied plt.titleC"Mars Pseudo-Color Image") plt. shaw) Restore original file Save & Grade Unlimited attempts Submitted answer 2 371e56baba311fca21f25fc69 6ac5fab@ondemand~e3J2TKAUEeqwwg4Kh- 100' [100% | hide ~ 2LYQ::clid=153371 submitted at 2024-05-09 22:46:55 (CDT) Score: 1/1 (100%) Figure