Commit 92971b0f authored by Andrew Lyon's avatar Andrew Lyon
Browse files

Change output condensate_masks_color.tif so that three color images are output...

Change output condensate_masks_color.tif so that three color images are output with binary pixel values indicating whether a pixel is in the dense phase (red), dilute phase (green), or background (blue).
parent 36df7727
......@@ -562,16 +562,19 @@ def main(args):
exposure.rescale_intensity(sum_droplet[zplane, :, :], out_range=(0., 1.)))
# Get image of same shape as cropped_droplet with non-dilute phase pixels set to 0
dilute_color = np.zeros(cropped_droplet.shape, dtype='uint8')
dilute_color[dilute_mask] = cropped_droplet[dilute_mask]
dilute_color[dilute_mask] = 1
# dilute_color[dilute_mask] = cropped_droplet[dilute_mask]
dilute_phase_color.append((bbox, dilute_color))
# Get image of same shape as cropped_droplet with non-dense phase pixels set to 0
dense_color = np.zeros(cropped_droplet.shape, dtype='uint8')
dense_color[dense_mask] = cropped_droplet[dense_mask]
dense_color[dense_mask] = 1
# dense_color[dense_mask] = cropped_droplet[dense_mask]
dense_phase_color.append((bbox, dense_color))
# Get image of same shape as cropped_droplet with neither dilute nor dense phase pixels set to 0
none_color = np.zeros(cropped_droplet.shape, dtype='uint8')
none_mask = np.logical_not(np.logical_or(dilute_mask, dense_mask))
none_color[none_mask] = cropped_droplet[none_mask]
none_color[none_mask] = 1
# none_color[none_mask] = cropped_droplet[none_mask]
neither_phase_color.append((bbox, none_color))
# Append measured values to output lists
......@@ -589,23 +592,29 @@ def main(args):
if args.writeintermediates:
# Write the colored dense/dilute phase mask image
for dilute in dilute_phase_color:
# Dimension 2 is blue channel for RGB image
# Dimension 1 is green channel for RGB image
# The droplet boundary is determined after the watershedding step so adding intensites for each droplet
# will not double count pixels
img_color_mask[dilute[0][0]:dilute[0][2], dilute[0][1]:dilute[0][3], 2] += dilute[1]
img_color_mask[dilute[0][0]:dilute[0][2], dilute[0][1]:dilute[0][3], 1] += dilute[1]
for neither in neither_phase_color:
# Dimension 1 is green channel
# Dimension 2 is blue channel
# The pixels in each cropped droplet image outside the dilute phase mask get double counted
# if the intensities are added. Zeroing out the green pixels if they overlap with red or blue pixels
# after building the image seems like the best way to handle this.
img_color_mask[neither[0][0]:neither[0][2], neither[0][1]:neither[0][3], 1] = neither[1]
img_color_mask[neither[0][0]:neither[0][2], neither[0][1]:neither[0][3], 2] = neither[1]
for dense in dense_phase_color:
# Dimension 0 is red channel The dense phase is strictly contained inside the dilute phase mask so
# adding intensities for each droplet will not double count pixels
img_color_mask[dense[0][0]:dense[0][2], dense[0][1]:dense[0][3], 0] += dense[1]
# Zero out green pixels overlapping with red or blue pixels
img_color_mask[img_color_mask[:, :, 0] > 0, 1] = 0
img_color_mask[img_color_mask[:, :, 2] > 0, 1] = 0
# Zero out blue pixels overlapping with red or green pixels
img_color_mask[img_color_mask[:, :, 0] > 0, 2] = 0
img_color_mask[img_color_mask[:, :, 1] > 0, 2] = 0
for r in range(n_row):
for c in range(n_col):
# If all pixels are 0
if np.all(img_color_mask[r, c, :] == 0):
# pixel is background so set blue channel to 1
img_color_mask[r, c, 2] = 1
step += 1
img_name = os.path.join(img_base_name, img_base_name + "_" + str(step) + "_condensate_masks_color" +
".tif")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment