Skip to content

Instantly share code, notes, and snippets.

View Nullkooland's full-sized avatar
:shipit:
->chirp()

Yunshan Nullkooland

:shipit:
->chirp()
View GitHub Profile
@Nullkooland
Nullkooland / jet.py
Created November 23, 2021 13:26
PyTorch colormap mappings
# JET colormap
# See https://stackoverflow.com/questions/7706339/grayscale-to-red-green-blue-matlab-jet-color-scale
def _get_colormap_jet(x: Tensor) -> Tensor:
# x has value range [0, 1]
r = torch.clamp(1.5 - torch.abs(4 * x - 3.0), 0.0, 1.0) # -> [bs, 1, h, w]
g = torch.clamp(1.5 - torch.abs(4 * x - 2.0), 0.0, 1.0) # -> [bs, 1, h, w]
b = torch.clamp(1.5 - torch.abs(4 * x - 1.0), 0.0, 1.0) # -> [bs, 1, h, w]
return torch.cat((r, g, b), dim=1) # -> [bs, 3, h, w]
@Nullkooland
Nullkooland / ncc.py
Last active August 30, 2021 14:23
PyTorch implementation of 2d normalized cross-correlation (NCC)
import torch
import torch.nn as nn
import torch.nn.functional as F
class NormalizedCrossCorrelation2d(nn.Module):
def __init__(self):
super(NormalizedCrossCorrelation2d, self).__init__()
def forward(self, x: torch.Tensor, template: torch.Tensor) -> torch.Tensor:
# Do image-wise normalization
@Nullkooland
Nullkooland / build.sh
Last active January 6, 2021 14:31
Cross compilation of OpenCV for aarch64 Linux platform with LLVM
cmake .. \
-G "Unix Makefiles" \
-D CMAKE_TOOLCHAIN_FILE=toolchain.cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_SHARED_LIBS=ON \
-D CMAKE_INSTALL_PREFIX="/usr" \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D CPU_BASELINE=NEON \
-D OPENCV_ENABLE_NONFREE=OFF \
@Nullkooland
Nullkooland / .clang-format
Created December 27, 2020 08:57
My ClangFormat configuration
BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 4
DerivePointerAlignment: false
PointerAlignment: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
AlignOperands: true
AlignAfterOpenBracket: true
@Nullkooland
Nullkooland / build_ffmpeg_rockchip.sh
Last active October 17, 2023 14:11
Cross-compile FFmpeg for rockchip ARM platform using LLVM toolchain on macOS
export ARCH=armv7
export CPU=armv7-a
export OS=linux
export TARGET=armv7-linux-gnueabihf
export SYSROOT=../sysroot
export PREFIX=/usr
export TOOLCHAIN=/usr/local/opt/llvm/bin
export CC=$TOOLCHAIN/clang
export CXX=$TOOLCHAIN/clang++