#StackBounty: #python #image-processing Get mask of image without using OpenCV

Bounty: 150

I’m trying the following to get the mask out of this image, but unfortunately I fail.

import numpy as np
import skimage.color
import skimage.filters
import skimage.io

# get filename, sigma, and threshold value from command line
filename = 'pathToImage'

# read and display the original image
image = skimage.io.imread(fname=filename)
skimage.io.imshow(image)
# blur and grayscale before thresholding
blur = skimage.color.rgb2gray(image)
blur = skimage.filters.gaussian(blur, sigma=2)
# perform inverse binary thresholding
mask = blur < 0.8
# use the mask to select the "interesting" part of the image
sel = np.ones_like(image)
sel[mask] = image[mask]

# display the result
skimage.io.imshow(sel)

How can I obtain the mask?

enter image description here enter image description here

Is there a general approach that would work for this image as well. without custom fine-tuning and changing parameters?
enter image description here


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.