stimupy.utils.contrast_conversions#

Functions#

transparency

Applies a transparency to image at specified (mask) location if provided

adapt_michelson_contrast

Adapt Michelson contrast of image

adapt_rms_contrast

Adapt rms contrast of image (std)

adapt_normalized_rms_contrast

Adapt normalized rms contrast of image (std divided by mean)

adapt_intensity_range

Adapt intensity range of image

adapt_michelson_contrast_dict

Adapt Michelson contrast of image in dict

adapt_rms_contrast_dict

Adapt rms contrast of image (std)

adapt_normalized_rms_contrast_dict

Adapt normalized rms contrast of image (std divided by mean)

adapt_intensity_range_dict

Adapt intensity range of image

transparency(img, mask=None, alpha=0.5, tau=0.2)[source]#

Applies a transparency to image at specified (mask) location if provided

Parameters:
  • img (np.array) – image to which transparency will be applied

  • mask (np.array or None (default)) – if not None, transparency will be provided at non-zero locations provided in this mask

  • alpha (Number) – alpha of transparency (i.e. how transparent the medium is), default 0.2

  • tau (Number) – tau of transparency (i.e. value of transparent medium), default 0.5

Return type:

img with the applied transparency

adapt_michelson_contrast(img, michelson_contrast, mean_luminance=None)[source]#

Adapt Michelson contrast of image

Parameters:
  • img (np.ndarray) – stimulus array

  • michelson_contrast (float) – desired Michelson contrast

  • mean_luminance (float) – desired mean luminance; if None (default), dont change mean luminance

Returns:

img – image with adapted michelson contrast and mean luminance if passed

Return type:

np.ndarray

adapt_rms_contrast(img, rms_contrast, mean_luminance=None)[source]#

Adapt rms contrast of image (std)

Parameters:
  • img (np.ndarray) – stimulus array

  • rms_contrast (float) – desired rms contrast (std divided by mean intensity)

  • mean_luminance (float) – desired mean luminance; if None (default), dont change mean luminance

Returns:

img – image with adapted rms contrast and mean luminance if passed

Return type:

np.ndarray

adapt_normalized_rms_contrast(img, rms_contrast, mean_luminance=None)[source]#

Adapt normalized rms contrast of image (std divided by mean)

Parameters:
  • img (np.ndarray) – stimulus array

  • rms_contrast (float) – desired rms contrast (std divided by mean intensity)

  • mean_luminance (float) – desired mean luminance; if None (default), dont change mean luminance

Returns:

img – image with adapted rms contrast and mean luminance if passed

Return type:

np.ndarray

adapt_intensity_range(img, intensity_min=0.0, intensity_max=1.0)[source]#

Adapt intensity range of image

Parameters:
  • img (np.ndarray) – stimulus array

  • intensity_min (float) – new minimal intensity value

  • intensity_max (float) – new maximal intensity value

Returns:

img – image with adapted intensity range

Return type:

np.ndarray

adapt_michelson_contrast_dict(stim, michelson_contrast, mean_luminance=None)[source]#

Adapt Michelson contrast of image in dict

Parameters:
  • stim (dict) – stimulus dictionary containing at least key “img”

  • michelson_contrast (float) – desired Michelson contrast

  • mean_luminance (float) – desired mean luminance; if None (default), dont change mean luminance

Returns:

dict with the stimulus (key: “img”), Michelson contrast (key: “michelson_contrast”), mean luminance (“mean_luminance”) and additional keys containing stimulus parameters

Return type:

dict[str, Any]

adapt_rms_contrast_dict(stim, rms_contrast, mean_luminance=None)[source]#

Adapt rms contrast of image (std)

Parameters:
  • stim (dict) – stimulus dictionary containing at least key “img”

  • rms_contrast (float) – desired rms contrast (std divided by mean intensity)

  • mean_luminance (float) – desired mean luminance; if None (default), dont change mean luminance

Returns:

dict with the stimulus (key: “img”), RMS contrast (key: “rms_contrast”), mean luminance (“mean_luminance”) and additional keys containing stimulus parameters

Return type:

dict[str, Any]

adapt_normalized_rms_contrast_dict(stim, rms_contrast, mean_luminance=None)[source]#

Adapt normalized rms contrast of image (std divided by mean)

Parameters:
  • stim (dict) – stimulus dictionary containing at least key “img”

  • rms_contrast (float) – desired rms contrast (std divided by mean intensity)

  • mean_luminance (float) – desired mean luminance; if None (default), dont change mean luminance

Returns:

dict with the stimulus (key: “img”), RMS contrast (key: “rms_contrast”), mean luminance (“mean_luminance”) and additional keys containing stimulus parameters

Return type:

dict[str, Any]

adapt_intensity_range_dict(stim, intensity_min=0.0, intensity_max=1.0)[source]#

Adapt intensity range of image

Parameters:
  • stim (dict) – stimulus dictionary containing at least key “img”

  • intensity_min (float) – new minimal intensity value

  • intensity_max (float) – new maximal intensity value

Returns:

dict with the stimulus (key: “img”), intensity range (key: “intensity_range”), and additional keys containing stimulus parameters

Return type:

dict[str, Any]