Skip to content

Commit

Permalink
add normalization options
Browse files Browse the repository at this point in the history
  • Loading branch information
chiarasch committed Aug 5, 2024
1 parent ba1b38f commit f2ef547
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions scripts/phenoimager2mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,25 @@ def getOptions(myopts=None):
required=True,
type=int,
help="Provide number of markers in the image.")
standard.add_argument(
"-n",
"--normalization",
dest="normalization",
action="store",
required=False,
default="99th",
choices=["99th", "max"],
help="Provide method to normalize marker intensities per channel. Options = [99th, max]")

# Tool Output
output = parser.add_argument_group(title='Required output')
output.add_argument("-o",
"--output",
dest="output",
action='store',
required=True,
help="Output file, existing or will be newly created.")
output.add_argument(
"-o",
"--output",
dest="output",
action='store',
required=True,
help="Output file, existing or will be newly created.")

args = parser.parse_args(myopts)

Expand Down Expand Up @@ -136,8 +146,13 @@ def normalize_image(output_file):

# Normalize each channel separately
for ch in range(img.shape[1]): # Now channels are the second dimension
percentile_99 = np.percentile(img[:, ch, :], 99)
img_normalized[:, ch, :] = img[:, ch, :] / percentile_99
if args.normalization == "99th":
percentile_99 = np.percentile(img[:, ch, :], 99)
img_normalized[:, ch, :] = img[:, ch, :] / percentile_99

elif args.normalization == "max":
img_normalized[:, ch, :] = img[:, ch, :] / np.max(img[:, ch, :])

img_normalized[:,
ch, :][img_normalized[:,
ch, :] > 1] = 1 # Cap values at 1
Expand Down

0 comments on commit f2ef547

Please sign in to comment.