reframe comments
@@ -68,34 +68,31 @@ def read_narrow_png(file_name, step_size=0.1):
image_array = mpimg.imread(file_name)
- # AVG ACROSS NARROW DIMENSION & COLORS
- if image_array.shape[0] > 5*image_array.shape[1]: # VERTICAL
+ # DIMENSIONS TO AVG ACROSS DIFFERENT FOR HORIZ VS VERT IMG
+ if image_array.shape[0] > 5*image_array.shape[1]: # VERT
image_vector = np.average(image_array, axis=(1, 2))
pixel_size_in_cm = (2.54 / dpi_vert)
- elif image_array.shape[1] > 5*image_array.shape[0]: # HORIZONTAL
+ elif image_array.shape[1] > 5*image_array.shape[0]: # HORIZ
image_vector = np.average(image_array, axis=(0, 2))
pixel_size_in_cm = (2.54 / dpi_horiz)
else:
raise ValueError('The PNG file is not a narrow strip.')
assert step_size > 5 * pixel_size_in_cm, "step size too small"
- # ENFORCE ODD NUMBER OF PIXELS, SO PROFILE CENTER IS MID-PIXEL
if image_vector.shape[0] % 2 == 0:
- image_vector = image_vector[:-1]
+ image_vector = image_vector[:-1] # SO ZERO DISTANCE IS MID-PIXEL
- # FIND THE UN-DOWNSAMPLED DISTANCES
length_in_cm = image_vector.shape[0] * pixel_size_in_cm
- image_vector_distances = np.arange(-length_in_cm/2,
+ full_resolution_distances = np.arange(-length_in_cm/2,
length_in_cm/2,
pixel_size_in_cm)
- # DOWNSAMPLE THE IMAGE VECTOR DISTANCES
+ # TO MOVE FROM FILM RESOLUTION TO DESIRED PROFILE RESOLUTION
num_pixels_to_avg_over = int(step_size/pixel_size_in_cm)
-
sample_indices = np.arange(num_pixels_to_avg_over/2,
- len(image_vector_distances),
+ len(full_resolution_distances),
num_pixels_to_avg_over).astype(int)
- downsampled_distance = list(image_vector_distances[sample_indices])
+ downsampled_distances = list(full_resolution_distances[sample_indices])
downsampled_density = []
for idx in sample_indices: # AVERAGE OVER THE SAMPLING WINDOW
@@ -104,6 +101,5 @@ def read_narrow_png(file_name, step_size=0.1):
int(idx + num_pixels_to_avg_over / 2)])
downsampled_density.append(avg_density)
- # ZIP & RETURN
- density_profile = list(zip(downsampled_distance, downsampled_density))
- return density_profile
+ zipped_profile = list(zip(downsampled_distances, downsampled_density))
+ return zipped_profile
