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

Histogram Backprojection #979

Closed
wants to merge 2 commits into from

Conversation

abidrahmank
Copy link

This is an implementation of Histogram Backprojection based on:
Swain, Michael J., and Dana H. Ballard. "Indexing via color histograms." Active Perception and Robot Vision. Springer Berlin Heidelberg, 1992. 261-273.

(This was submitted one year ago, reviewed and certified OK, but somehow I corrupted my git repo, so merging was not possible back then. So I am resending the same)

figure_1


# Both images should be single or 3-channel
assert len(shape1) == len(shape2),\
"both images should be 1-channel or 3-channel"
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is actually asserting "Both images should have the same number of dimensions," not specifying 1 or 3. I recommend changing to shape1 == shape2 if both images must have equivalent shape, otherwise omitting this check and changing the API (see below).

Channels are generally stored in the third dimension when present, but often grayscale images omit the 'channels' dimension so it's difficult to distinguish automatically between a very small/thin image and one which is supposedly RGB. For example, a 2D image would usually be of shape (M, N), not (M, N, 1); in contrast an RGB image would usually be of shape (M, N, 3). Checking .shape[-1] might work, but what if the image is grayscale and happens to have N == 3? The check breaks down. Thus, we usually ask the user to tell us if an image is multichannel or not.

skimage.segmentation.slic shows our current consensus API, I believe: a boolean multichannel= kwarg switches between code paths.

@JDWarner
Copy link
Contributor

Thank you for bringing this back @abidrahmank ! I left a couple minor comments about API/input checks because we've come to some consensus about this since the previous backprojection PR.

Your error in Travis for Python3 is because the skimage.io backend TravisCI uses in Python 3.x loads everything as a floating point image, whereas Python 2.x generally returns the actual file dtype. You'll need to add an img_as_ubyte step to the loaded dataset in the example, or in the function instead of just checking that inputs are of type np.uint8 actually perform img_as_ubyte there (my preference).

========================

Histogram Backprojection is a tool for image segmentation, object tracking
etc. based on object's color distribution..
Copy link
Member

Choose a reason for hiding this comment

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

two full stops

@stefanv
Copy link
Member

stefanv commented Apr 11, 2014

Clearly, I am confused as to what exactly histogram backprojection is, which is why we need a good explanation in the gallery!

@abidrahmank
Copy link
Author

Its main use is segmentation based on the color properties of the object. Say, you know the color properties (color histogram) of a region (or small part of the region) you want to segment. You backproject it to the original image to segment out the full region. It is more like "Color Tool" in GIMP. (But honestly, I can demonstrate it, but don't know how to explain it. One more example here: http://opencvpython.blogspot.in/2013/03/histograms-4-back-projection.html)

@abidrahmank
Copy link
Author

@JDWarner : regarding img_as_ubyte, it can convert only float data to uint8, right? Then isn't it better to tell the user do that conversion? ( I mean, converting float to uint8 in example)?

@stefanv
Copy link
Member

stefanv commented Apr 11, 2014

@abidrahmank Your description there is perfect!

Here's a first attempt using my new-found understanding :)

Histogram back-projection is a method for segmentation based on a marked region of the object of interest. The histogram properties of that region is computed, and used to identify parts of the image that correspond closely.

Parameters
----------
img1 : array
Image array on which img2 is backprojected
Copy link
Member

Choose a reason for hiding this comment

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

Image containing the object to be segmented.

@abidrahmank
Copy link
Author

@stefanv : yeah... that is it :)

----------
img1 : array
Image array on which img2 is backprojected
img2 : array
Copy link
Member

Choose a reason for hiding this comment

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

object_image : (M, N, 3) ndarray
    Image that represents the object.  This can either be a slice from the object in the original image,
    or the input image with all areas outside the object set to 0.  [<-- can we make it work that way?  Then
    we support masks, which is cool.]

@stefanv
Copy link
Member

stefanv commented Apr 11, 2014

Minor update to that description to emphasize that we seek correspondence, not difference.

@stefanv
Copy link
Member

stefanv commented Apr 11, 2014

"We are no longer using Vagrant for our backend, and as such we aren't maintaining the Vagrant images. We're looking into a way of doing this, but for now you can email us at support AT travis-ci.org and we can spin up a debug VM for you if you need to debug an issue."

@stefanv
Copy link
Member

stefanv commented Apr 11, 2014

I'll go ahead and ping them.

@stefanv
Copy link
Member

stefanv commented Oct 20, 2014

What is the status of this PR?

@abidrahmank
Copy link
Author

I will try to finish this weekend.
On Oct 21, 2014 4:49 AM, "Stefan van der Walt" notifications@github.com
wrote:

What is the status of this PR?


Reply to this email directly or view it on GitHub.

@sciunto sciunto self-assigned this Apr 15, 2017
@sciunto sciunto mentioned this pull request Dec 15, 2018
14 tasks
@sciunto
Copy link
Member

sciunto commented Dec 15, 2018

This PR is continued in another branch, to take recent developments into account.

@sciunto sciunto closed this Dec 15, 2018
@sciunto
Copy link
Member

sciunto commented Dec 15, 2018

Thank you @abidrahmank for the implementation.

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

5 participants