Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a code snippet that shows how to use <a href="http://scikit-image.org" rel="noreferrer">scikit-image</a> to overlay colors on a grey-level image. The idea is to convert both images to the HSV color space, and then to replace the hue and saturation values of the grey-level image with those of the color mask.</p> <pre><code>from skimage import data, color, io, img_as_float import numpy as np import matplotlib.pyplot as plt alpha = 0.6 img = img_as_float(data.camera()) rows, cols = img.shape # Construct a colour image to superimpose color_mask = np.zeros((rows, cols, 3)) color_mask[30:140, 30:140] = [1, 0, 0] # Red block color_mask[170:270, 40:120] = [0, 1, 0] # Green block color_mask[200:350, 200:350] = [0, 0, 1] # Blue block # Construct RGB version of grey-level image img_color = np.dstack((img, img, img)) # Convert the input image and color mask to Hue Saturation Value (HSV) # colorspace img_hsv = color.rgb2hsv(img_color) color_mask_hsv = color.rgb2hsv(color_mask) # Replace the hue and saturation of the original image # with that of the color mask img_hsv[..., 0] = color_mask_hsv[..., 0] img_hsv[..., 1] = color_mask_hsv[..., 1] * alpha img_masked = color.hsv2rgb(img_hsv) # Display the output f, (ax0, ax1, ax2) = plt.subplots(1, 3, subplot_kw={'xticks': [], 'yticks': []}) ax0.imshow(img, cmap=plt.cm.gray) ax1.imshow(color_mask) ax2.imshow(img_masked) plt.show() </code></pre> <p>Here's the output:</p> <p><img src="https://i.stack.imgur.com/9d1Qd.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload