Skip to content

HOG enhancement to accept color images - #1963

Closed
pradyumnanpk wants to merge 2 commits into
scikit-image:masterfrom
pradyumnanpk:hog-color_image-enhancement
Closed

pradyumnanpk wants to merge 2 commits into
scikit-image:masterfrom
pradyumnanpk:hog-color_image-enhancement

Conversation

@pradyumnanpk

Copy link
Copy Markdown
Contributor

I implemented the HOG for color images based on the excerpt from the original paper "For colour images, we calculate separate gradients for each colour channel, and take the one with the largest norm
as the pixel’s gradient vector"[Dalal and Triggs] and the CVPR presentation "For color image, pick the color channel with the highest gradient magnitude for each pixel"[Dalal and Triggs].

To allow this change, I refactored the code so that image gradients are computed in a separate method. If the image has more than 1 channels, this method is called on each channel. Gradient magnitude is calculated for each channel and for each pixel, the gradient vector with maximum magnitude is considered.

This is my first open source contribution and I implemented the change based on my understanding. Please review my code and let me know if I implemented the functionality correctly. Please comment on coding style too.

@vighneshbirodkar

Copy link
Copy Markdown
Contributor

@pradyumnanpk Thanks for your work
Please always reference the issue you are trying to fix (if there is any), in this case #1879

Comment thread skimage/feature/_hog.py
gy = np.empty(image.shape[0:2], dtype=np.double)

max_index_array = gradient.argmax(axis = 2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you want to iterate over arrays, you should use Cython, with that said this can be done in numpy itself. I believe you are trying to index one array with the maximum index along
the 3rd axis found elsewhere

import numpy as np

a = np.random.random((10, 10, 3))*10
a = a.astype(np.int)

index = np.random.random((10, 10))*3
index = index.astype(np.int)
rr, cc = np.meshgrid(np.arange(a.shape[0]), np.arange(a.shape[1]))
b = a[rr, cc, index]

print(b)

@vighneshbirodkar

Copy link
Copy Markdown
Contributor

Apart from the slow indexing loops, I think this looks good. You will also need to remove the unnecessary test.

It will also help the users a lot if you modify the existing examples to show a color image.

@pradyumnanpk

Copy link
Copy Markdown
Contributor Author

Hi Vignesh,

Thanks a lot for the feedback. I changed my code accordingly. Please have a look at it and let me know if there are any other optimizations or changes.

I want to write a test case or output correctness of a color image. Can you tell me how to generate a correct output for a color image?

Comment thread skimage/feature/_hog.py Outdated

for row_index, row in enumerate(max_index_array):
for col_index, value in enumerate(row):
gx[row_index][col_index] = channel_gradients[value][0][row_index][col_index]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you wrap this to 80 chars ?

Please follow PEP8 styling guidelines.
You can use flake8 or autopep8 for help

@vighneshbirodkar

Copy link
Copy Markdown
Contributor

Hi @pradyumnanpk
It is Vighnesh

I am sorry, I am not familiar with the literature to help you for the test case. Maybe you can ping those who commented on the original issue ?

@soupault soupault added the ⏩ type: Enhancement Improve existing features label Feb 27, 2016
@soupault soupault mentioned this pull request Nov 4, 2017
7 tasks done
@soupault

soupault commented Nov 4, 2017

Copy link
Copy Markdown
Member

@pradyumnanpk thanks for the contribution!
I've opened a new PR where your changes are rebased, refactored in accordance with skimage conventions, and supplemented with a test and a gallery example update.
Closing in advance of #2870.

@soupault soupault closed this Nov 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⏩ type: Enhancement Improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants