Skip to content

Commit 1972e32

Browse files
committed
Add README text, set fPIC by force
1 parent abe34b0 commit 1972e32

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ set(CMAKE_CXX_STANDARD 17)
1414
file(GLOB HOG_SOURCES "src/hog.cpp")
1515
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
1616
add_library(hog_sse4 OBJECT src/magnitude_orientation.cpp)
17+
set_property(TARGET hog_sse4 PROPERTY POSITION_INDEPENDENT_CODE ON)
1718
target_compile_options(hog_sse4 PRIVATE -msse4 -DVEC_T=Vec2d)
1819
target_include_directories(hog_sse4 PRIVATE ${HOG_INCLUDES})
1920

2021
add_library(hog_avx2 OBJECT src/magnitude_orientation.cpp)
22+
set_property(TARGET hog_avx2 PROPERTY POSITION_INDEPENDENT_CODE ON)
2123
target_compile_options(hog_avx2 PUBLIC -mavx2 -mfma -DVEC_T=Vec4d)
2224
target_include_directories(hog_avx2 PRIVATE ${HOG_INCLUDES})
2325

2426
add_library(hog_avx512 OBJECT src/magnitude_orientation.cpp)
27+
set_property(TARGET hog_avx512 PROPERTY POSITION_INDEPENDENT_CODE ON)
2528
target_compile_options(hog_avx512 PUBLIC -mavx512f -mfma -DVEC_T=Vec8d)
2629
target_include_directories(hog_avx512 PRIVATE ${HOG_INCLUDES})
2730

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# FastHOG
2-
Reasonably fast implementation of Histogram of Oriented Gradients.
2+
Reasonably fast implementation of Histogram of Oriented Gradients. Designed to be roughly equivalent to
3+
`skimage.feature.hog`. While slightly less flexible (it only supports `float64` single-channel images),
4+
it is _significantly_ faster, so ideal in workloads where `HOG` calculation is a bottleneck, as was in
5+
the https://github.com/flatironinstitute/ManifoldEM project that inspired this repository.
6+
7+
8+
## Installation
9+
10+
```bash
11+
pip install fasthog
12+
```
13+
14+
## Usage
15+
Example taken from https://scikit-image.org/docs/stable/auto_examples/features_detection/plot_hog.html
16+
17+
```python3
18+
from fasthog import hog
19+
from skimage import data
20+
from skimage.color import rgb2gray
21+
22+
image = rgb2gray(data.astronaut())
23+
24+
fd, hog_image = hog(
25+
image,
26+
n_bins=8,
27+
pixels_per_cell=(16, 16),
28+
cells_per_block=(1, 1),
29+
)
30+
31+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)
32+
33+
ax1.axis('off')
34+
ax1.imshow(image, cmap=plt.cm.gray)
35+
ax1.set_title('Input image')
36+
37+
# Rescale histogram for better display
38+
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))
39+
40+
ax2.axis('off')
41+
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
42+
ax2.set_title('Histogram of Oriented Gradients')
43+
plt.show()
44+
45+
46+
```

0 commit comments

Comments
 (0)