Repository navigation
HOG enhancement to accept color images - #1963
pradyumnanpk wants to merge 2 commits into
Conversation
|
@pradyumnanpk Thanks for your work |
| gy = np.empty(image.shape[0:2], dtype=np.double) | ||
|
|
||
| max_index_array = gradient.argmax(axis = 2) | ||
|
|
There was a problem hiding this comment.
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)|
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. |
|
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? |
|
|
||
| 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] |
There was a problem hiding this comment.
Could you wrap this to 80 chars ?
Please follow PEP8 styling guidelines.
You can use flake8 or autopep8 for help
|
Hi @pradyumnanpk 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 ? |
|
@pradyumnanpk thanks for the contribution! |
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.