Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for images that have completely black background #4

Open
yilangpeng opened this issue Jul 6, 2017 · 4 comments
Open

Error for images that have completely black background #4

yilangpeng opened this issue Jul 6, 2017 · 4 comments

Comments

@yilangpeng
Copy link

yilangpeng commented Jul 6, 2017

Both cases are about mdb.

(1)
fruit3-fr

Traceback (most recent call last):
File ".../demo.py", line 54, in
mbd = psal.get_saliency_mbd(filename).astype('uint8')
File ".../saliency_mbd.py", line 169, in get_saliency_mbd
cov_bottom = np.linalg.inv(cov_bottom)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 526, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix

(2)
Another example is a white background image:
sushi6-st copy

raises warning
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/skimage/io/_io.py:132: UserWarning: sushi6-ST copy-mbd.png is a low contrast image
warn('%s is a low contrast image' % fname)

The saliency map is also strange (completely black).
sushi6-st copy-mbd

However, if I add some elements to its background, it works fine and results in a good saliency map.
sushi6-st

sushi6-st-mbd

@RoseLii
Copy link

RoseLii commented Nov 8, 2017

please help me
ImportError: No module named pyimgsaliency

@tymdgit
Copy link

tymdgit commented Feb 27, 2018

I have same errors and it is very critical, your module would be very useful but we cannot use your work until this is fixed.

################ versions ##########################

python 3.5.2
numpy 1.13.3
scipy 1.0.0
sklearn 0.19.1

################ codes ##########################

image_path = "chem.png" # also tried with jpg version : image_path = "chem.jpg"

mbd = psal.get_saliency_mbd(image_path).astype('uint8')
pi_mbd = ProcessedImage(mbd)
pi_mbd.image.show()

######################## image #################

chem

########## error ########################

--> 513 ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
514 return wrap(ainv.astype(result_t, copy=False))
515
~/tfenv/lib/python3.5/site-packages/numpy/linalg/linalg.py in _raise_linalgerror_singular(err, flag)
88
89 def _raise_linalgerror_singular(err, flag):
---> 90 raise LinAlgError("Singular matrix")
91
92 def _raise_linalgerror_nonposdef(err, flag):

LinAlgError: Singular matrix

@brian36
Copy link

brian36 commented Jun 15, 2018

A simple work-around that worked for me is to use the pseudo inverse in these cases. I.e., for each one:

        try:
            cov_left = np.linalg.inv(cov_left)
        except:
            cov_left = np.linalg.pinv(cov_left)

@angelinimattia
Copy link

angelinimattia commented Sep 16, 2020

Is normal to have errors in flat color image with saliency methods due to the need to calculate the inverse matrix of image pieces, is something discussed even in literature, a solid fix is to add some noise to the image :

//untested
noise_mat = np.random.randint(4, size=img.size) - 2
img = np.clip(img + noise_mat , 0, 255) // avoid to have colors outside the valid range

this should do the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants