Skip to content

Commit

Permalink
Add README text, set fPIC by force
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwer committed Feb 5, 2025
1 parent abe34b0 commit 1972e32
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ set(CMAKE_CXX_STANDARD 17)
file(GLOB HOG_SOURCES "src/hog.cpp")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
add_library(hog_sse4 OBJECT src/magnitude_orientation.cpp)
set_property(TARGET hog_sse4 PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_options(hog_sse4 PRIVATE -msse4 -DVEC_T=Vec2d)
target_include_directories(hog_sse4 PRIVATE ${HOG_INCLUDES})

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

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

Expand Down
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# FastHOG
Reasonably fast implementation of Histogram of Oriented Gradients.
Reasonably fast implementation of Histogram of Oriented Gradients. Designed to be roughly equivalent to
`skimage.feature.hog`. While slightly less flexible (it only supports `float64` single-channel images),
it is _significantly_ faster, so ideal in workloads where `HOG` calculation is a bottleneck, as was in
the https://github.com/flatironinstitute/ManifoldEM project that inspired this repository.


## Installation

```bash
pip install fasthog
```

## Usage
Example taken from https://scikit-image.org/docs/stable/auto_examples/features_detection/plot_hog.html

```python3
from fasthog import hog
from skimage import data
from skimage.color import rgb2gray

image = rgb2gray(data.astronaut())

fd, hog_image = hog(
image,
n_bins=8,
pixels_per_cell=(16, 16),
cells_per_block=(1, 1),
)

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)

ax1.axis('off')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Input image')

# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))

ax2.axis('off')
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients')
plt.show()


```

0 comments on commit 1972e32

Please sign in to comment.