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

Shape contexts #921

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

sivapvarma
Copy link
Contributor

Shape Contexts

paper link: http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/belongie-pami02.pdf

refactor of code from PR#235 to make it more efficient and documentation

Current API :

import numpy as np
from skimage.feature import descriptor_shapecontext
img = np.zeros((20, 20)).astype(float)
img[4:8, 4:8] = 1
px = (10, 10)
print descriptor_shapecontext(img, 0, 25, px, radial_bins=3, polar_bins=4)

radial_bins : integer
number of log r bins in log-r vs theta histogram

polar_bins : integer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, write int instead of integer
Here, write "int, optional"

@sivapvarma
Copy link
Contributor Author

Update: build now passes :-)

current_pixel : int tuple, (r, c)
the pixel for which to find shape context descriptor

radial_bins : int, optional (default: 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put the default value in the line below please?

@sciunto
Copy link
Member

sciunto commented Mar 13, 2014

Cool. I just scrooled the paper, it looks really interesting. Is it possible to make an example for the gallery? (see doc/examples)

Core dev may have other comments. I have not read the code in details yet :)

@sivapvarma
Copy link
Contributor Author

@sciunto I want to add the MNIST classification results of the paper which was the best on that dataset at the time the paper was published in 2002. They still are the best features with kNN classifier on MNIST. I may need to use sklearn.neighbors.KNeighborsClassifier and the pre-processing required to get 0.63 classification rate on MNIST is a bit involved. So it'll mostly become a lengthy demonstration than an example.

of histogram from current_pixel

r_min : float
minmimum distance of the pixels that are considered in computation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling error

@RONNCC
Copy link
Contributor

RONNCC commented Mar 13, 2014

also +1 for the gallery addition, this is a cool paper!

@stefanv
Copy link
Member

stefanv commented Mar 13, 2014

Perhaps a better place for such a demo would be
https://github.com/stefanv/scikit-image-demos.git for now. I could move
that repo to the scikit-image org if it is of more general interest.

Matching with Shape Contexts
http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/sc_digits.html

.. [2] Wikipedia, "Shape Contexts".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[3] ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehh yeah i was surprised too, but I guess it can't hurt if he learned what a shape context is there...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just included it for completeness since there is a wiki page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so in general we only cite the paper + if there's relevant source paper + if you looked at any code for reference but usually just the paper,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then i'll remove that reference

@jni
Copy link
Member

jni commented Mar 14, 2014

@stefanv I'd agree with that new home --- do we have any examples that use sklearn in the gallery? I'm guessing we don't want to introduce that dependency?

the pixel for which to find shape context descriptor

radial_bins : int, optional
number of log r bins in log-r vs theta histogram (default: 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, sorry @sivapvarma for conflicting advice, but we only put the default values in the docstring for Cython functions, where there is no way to discover them by introspection. For Python functions, we don't specify default values, as they can be guessed independently, and putting them in the docstring increases the likelihood that the docstring and the definition will get out of sync.

@sciunto correct? Or am I missing something?

We do, however, start our docstring lines with a capital and end them with a full stop .. ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jni nope that sounds correct, other projects do this too, the default value still shows up in the function declaration + args when the docs are generated, so having them twice is redundant

@sivapvarma
Copy link
Contributor Author

@stefanv @jni I might be wrong but isn't doc/examples/applications on trunk currently intended to hold longer examples and demos.

@jni
Copy link
Member

jni commented Mar 14, 2014

@sivapvarma Yes, but notice that the examples there don't add any dependencies.

@stefanv
Copy link
Member

stefanv commented Mar 14, 2014

Wikipedia citations are okay, as long as the whole thing is given: title + url (also, I prefer to only use it if the article is actually any good)

@stefanv
Copy link
Member

stefanv commented Mar 14, 2014

@sivapvarma
Copy link
Contributor Author

I added an example. The images are from MNIST handwritten digits dataset.

@sivapvarma
Copy link
Contributor Author

I think the API can be improved a bit. descriptor_shapecontext() is a bit superfluous. shapecontext() should be enough. Also currently shapecontext.py doesn't do much, so I want to remove it, and let _shapecontext.pyx do everything.

If everybody agrees, I'll go ahead and make the changes

@sciunto
Copy link
Member

sciunto commented Mar 16, 2014

@jni well, OK.

@ahojnnes
Copy link
Member

We should keep the Python wrapper.

Also, to comply with the rest of the feature detectors / descriptors (e.g. BRIEF, ORB), I suggest to wrap it in a class. I know it's not necessary in case of shapecontext, but we should aim for consistency. In the long run we should also discuss if we want to change HOG and Daisy top the new interface.

But let's first discuss this.

@jni
Copy link
Member

jni commented Mar 16, 2014

@ahojnnes I'm -1 on adding classes when a functional interface works equally well. To be honest I'm still not clear on why BRIEF and ORB weren't working as functions...

The Shape Context descriptor was introduced by Serge Belongie and Jitendra
Malik.

The Shape Context descriptor caputures the coarse distribution of the rest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spell check

@hmaarrfk
Copy link
Member

@sivapvarma, do you know how to update your master branch and rebase onto that?

If not, we might be able to help get this ready if you "enable commits from maintainers" on the bottom of the right side bar.

Ultimately, we can always fork off your branch, but I feel there is more satisfaction if you get your orignal PR accepted start to finish 😄

@pep8speaks
Copy link

Hello @sivapvarma! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 23:80: E501 line too long (87 > 79 characters)
Line 27:80: E501 line too long (93 > 79 characters)

Line 26:3: E227 missing whitespace around bitwise or shift operator
Line 26:7: E225 missing whitespace around operator
Line 30:1: E402 module level import not at top of file
Line 31:3: E225 missing whitespace around operator
Line 31:5: E225 missing whitespace around operator
Line 31:7: E225 missing whitespace around operator
Line 32:1: E402 module level import not at top of file
Line 33:1: E402 module level import not at top of file
Line 34:7: E225 missing whitespace around operator

Line 15:1: E305 expected 2 blank lines after class or function definition, found 1
Line 15:3: E227 missing whitespace around bitwise or shift operator
Line 15:7: E225 missing whitespace around operator
Line 32:3: E225 missing whitespace around operator
Line 32:5: E225 missing whitespace around operator
Line 32:7: E225 missing whitespace around operator
Line 33:5: E113 unexpected indentation
Line 40:7: E225 missing whitespace around operator

Line 34:80: E501 line too long (89 > 79 characters)

Line 8:5: E741 ambiguous variable name 'I'
Line 17:5: E741 ambiguous variable name 'I'
Line 19:5: E741 ambiguous variable name 'I'

@sivapvarma
Copy link
Contributor Author

@hmaarrfk I rebased on to master and also allowed edits from maintainers.

Let me know if there is anything else.

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

Successfully merging this pull request may close these issues.

None yet