I'm running one of the examples from skimage documentation and struggling to find either the multiscale_basic_features referenced there as an attribute of the skimage.feature module or its current equivalent. Does anyone know what I can substitute it with in the following segment of their code?:
features_func = partial(feature.multiscale_basic_features, intensity=True, edges=False, texture=True,
sigma_min=sigma_min, sigma_max=sigma_max,
multichannel=True)
You probably need to upgrade your scikit-image version. That function was only added in 0.18.1.
Related
I'm new to using rdkit but can't find any forum posts online addressing this but I've been trying to use the functions in rdkit.Chem.Descriptors as follows:
from rdkit import Chem
mol = Chem.MolFromSmiles('CC')
Descriptors.MolWt(mol)
this should just return the molecular weight = 30.07 of the molecule simply and I took this from the documentation but it just gives me an error saying:
NameError: name 'Descriptors' is not defined
I have no idea why - I tried changing versions but this has made no difference. It seems to be an error inherent to all functions in the Descriptor class.
I've also tried explicitly importing the Descriptor submodule/class and this doesn't work either.
from rdkit.Chem import Descriptors
is the correct way to import module for this code to work
Hi I am a new to computer visionand stackoverflow and I have a problem with my python 3 program on Windows,as the cv2.findContours() function returns 2 instead of three values as in the documentation. I passed 2 values for return to solve the bug,the type of the first(image) is a list and that of the second (cnts)is an int32 but none of them is abled to be used in cv2.drawContours() without bugging here I use image as parameter in because it is the only list returned so I guess it is the contours list cv2.drawContours().So here is the code:
#This is the program for a document scanner so as to extract a document
#from any image and apply perspective transform to show it as final result
import numpy as np
import cv2
import imutils
from matplotlib import pyplot as plt
cap=cv2.VideoCapture(0)
ret,img=cap.read()
img1=img.copy()
cv2.imshow('Image',img1)
img1=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
img1=cv2.bilateralFilter(img1,7,17,17)
img1=cv2.Canny(img1,30,200)
image,cnts=cv2.findContours(img1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#cnts=np.asarray(cnts,dtype='uint8')
cnts=np.array(cnts)
cv2.imshow('Edge',img1)
print('cnts var data type',cnts.dtype)
#print("Hi")
img=cv2.drawContours(img,[image],-1,(255,255,0),3)
Here is the python idle shell result appearing now:
cnts var data type is int32
Traceback (most recent call last):
File "D:\PyCharm Projects\Test_1_docscanner.py", line 20, in <module>
img=cv2.drawContours(img,[image],-1,(255,255,0),3)
TypeError: contours is not a numpy array, neither a scalar
I got it working finally,the following I did:
First I had previously messed up with most of my environmental variables haven suppressed some system variables. So I with help of a friend I retrieved as much as I could and deleted those I had stupidly ignorantly created.
Secondly I uninstalled all other python versions(at least I tried) though it seems that I still see their icons around(they seem to be "undeletable") and even the one I was using(Python3.7.3). I then install Python 3.7.4.
Thirdly,and that must be the answer is that I added this line cnts=imutils.grab_contours(cnts) before the cv2.drawContours() functions. Getting this from imutils package from Adrian Rosebrock github. my code now works because of that line which helps to parse the contours for whatever cv2.drawContours() opencv version you are using thereby avoiding conflicts of versions originating from cv2.findContours() function used prior to cv2.drawContours().
In conclusion I tried imutils.grab_contours() previously to these changes on my python3.7.3 but it did not work. But I believe above all the combination of "cnts=imutils.grab_contours(cnts)" and the update to Python3.7.4,is what solved the issue.
Hope this is helpful
I am trying to use the resize function using aliasing exactly as described in the documentation: http://scikit-image.org/docs/dev/auto_examples/transform/plot_rescale.html
from skimage.transform import resize
im_test = resize(im_test, (im_test.shape[0] / 3, im_test.shape[1] / 3),anti_aliasing=True)
However this returns:
Scikit image: resize() got an unexpected keyword argument
'anti_aliasing'
What is the reason for this? Is anti_aliasing on by default? What is the best way to resize an image with anti aliasing if this function can't be used?
Checking the code here with git blame, it seems it was introduced on 19.09.2017.
The only release version supporting this currently should be: v0.13.1, which you will need then!
For checking, what kind of version you are using currently, i recommend opening your interpreter (of your used python-distribution) and do:
import skimage as sk
sk.__version__
# '0.13.0' i would not be able to use it, it seems
there are two sets of documentation
1) http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.resize
2)http://scikit-image.org/docs/0.11.x/api/skimage.transform.html#resize
the second one doesn't accept anti_aliasing as a parameter and is the 0.11 version, the one that accepts anti aliasing is 0.14
looks like older version uses a box filter while resizing,and all pixels have equal weight
The following code gives me the error present in the title :
from skimage.feature import peak_local_max
local_maxi = peak_local_max(imd,labels=iml,
indices=False,num_peaks_per_label=2)
Where imd is a "distance transformed image" which was obtained with :
from scipy import ndimage
imd = ndimage.distance_transform_edt(im)
im is the input binary image that I would like to later on segment with the watershed function of scikit-image. But to use this function properly, I first need to find the markers which will serve as the starting flooding points : that's what I'm trying to do with the 'peak_local_max' function.
Also, iml is the labeled version of im, that I got with :
from skimage.measure import label
iml = label(im)
I don't know what I've been doing wrong. Also, I've noticed that, the function seems to totally ignore its num_peaks argument. For instance, when I do :
local_maxi = peak_local_max(imd,labels=iml,
indices=True,num_peaks=1)
I always get the same number of peaks detected as when I set num_peaks=500 or num_peaks=np.inf. What am I missing here please ?
As #a_guest pointed out, my version of skimage wasn't matching with the version of the documentation I was referring to. The num_peaks_per_label argument is currently only available in the v0.13dev version. Updating my version to the dev version also fixed my problem with the num_peaks argument.
I have installed the official python bindings for OpenCv and I am implementing some standard textbook functions just to get used to the python syntax. I have run into the problem, however, that CvSize does not actually exist, even though it is documented on the site...
The simple function: blah = cv.CvSize(inp.width/2, inp.height/2) yields the error 'module' object has no attribute 'CvSize'. I have imported with 'import cv'.
Is there an equivalent structure? Do I need something more? Thanks.
It seems that they opted to eventually avoid this structure altogether. Instead, it just uses a python tuple (width, height).
To add a bit more to Nathan Keller's answer, in later versions of OpenCV some basic structures are simply implemented as Python Tuples.
For example in OpenCV 2.4:
This (incorrect which will give an error)
image = cv.LoadImage(sys.argv[1]);
grayscale = cv.CreateImage(cvSize(image.width, image.height), 8, 1)
Would instead be written as this
image = cv.LoadImage(sys.argv[1]);
grayscale = cv.CreateImage((image.width, image.height), 8, 1)
Note how we just pass the Tuple directly.
The right call is cv.cvSize(inp.width/2, inp.height/2).
All functions in the python opencv bindings start with a lowercased c even in the highgui module.
Perhaps the documentation is wrong and you have to use cv.cvSize instead of cv.CvSize ?
Also, do a dir(cv) to find out the methods available to you.