Skip to content

Instantly share code, notes, and snippets.

View ialhashim's full-sized avatar

Ibraheem Alhashim ialhashim

View GitHub Profile
@ialhashim
ialhashim / color_vibrance.py
Last active January 3, 2023 08:14
Apply color vibrance adjustments
# Copy from https://github.com/bbonik/image_enhancement/blob/f0c286a166443202d592b920b63ee6901a0ee727/source/image_enhancement.py#L1388
import numpy as np
from skimage import img_as_float
def change_color_saturation(
image_color,
image_ph_mask=None,
sat_degree=1.5,):
LOCAL_BOOST = 0.2
@ialhashim
ialhashim / eigen_matrix_helper.cpp
Created July 27, 2014 21:14
Eigen matrix helper functions - from and to std::vector and from and to file (Qt)
template<typename Scalar, typename Container>
inline static Eigen::Matrix<Scalar,-1,-1> toEigenMatrix( const Container& vectors ){
typedef typename Container::value_type VectorType;
typedef typename VectorType::value_type Scalar;
Eigen::Matrix<Scalar,-1,-1> M(vectors.size(), vectors.front().size());
for(size_t i = 0; i < vectors.size(); i++)
for(size_t j = 0; j < vectors.front().size(); j++)
M(i,j) = vectors[i][j];
return M;
}
@ialhashim
ialhashim / voronoi.hpp
Last active November 24, 2022 04:36
Header-only C++ implementation to generate Voronoi diagrams (nice data structure)
// Source: https://github.com/samkusin/gamelabs/tree/master/voronoi
// with a bug fix (ennetws)
/* Usage:
using namespace cinekine;
...
voronoi::Sites sites;
for(int i = 0; i < 5; i++) sites.push_back(voronoi::Vertex(rand()*xBound/RAND_MAX,rand()*yBound/RAND_MAX));
...
voronoi::Graph graph = voronoi::build(std::move(sites), xBound, yBound);
...
@ialhashim
ialhashim / random_colors.hpp
Created July 27, 2014 21:12
Random colors Qt
inline QVector<QColor> rndColors(int count){
QVector<QColor> colors;
float currentHue = 0.0;
for (int i = 0; i < count; i++){
colors.push_back( QColor::fromHslF(currentHue, 1.0, 0.5) );
currentHue += 0.618033988749895f;
currentHue = std::fmod(currentHue, 1.0f);
}
return colors;
}
@ialhashim
ialhashim / agora_linux_for_ai.cpp
Last active June 24, 2022 14:38
Modifications on the Agora on-premise SDK to enable AI applications
//
// Step 3: In the file 'AgoraSdk.cpp'
//
void AgoraSdk::videoFrameReceivedImpl(
agora::linuxsdk::uid_t uid,
const agora::linuxsdk::VideoFrame *pframe) const {
char uidbuf[65];
snprintf(uidbuf, sizeof(uidbuf), "%u", uid);
@ialhashim
ialhashim / LABP.hpp
Created August 29, 2015 06:30
Linear Angle Based Parameterization
#pragma once
// Linear angle based parameterization SGP '07 - c++ code
// Based on code by Rhaleb Zayer
#include "SurfaceMeshModel.h"
#include "SurfaceMeshHelper.h"
using namespace SurfaceMesh;
#include <Eigen/Core>
@ialhashim
ialhashim / Upsample.py
Last active October 19, 2020 14:48
Resize or interpolate tensors to any spatial dimension in Keras
import tensorflow as tf
import keras.backend as K
from keras.layers import Lambda
#
# Keras + TensorFlow
# Resize 'tensorA' to be of the same size as 'tensorB' using 'tf.image.resize_bilinear'
# Very useful for skip-connections and 'Concatenate' layers that might complain about being off by one column
# Only works when dimensions are provided since we use ' K.int_shape' that returns the static shape
#
@ialhashim
ialhashim / azure_kinect_capture.cpp
Last active August 26, 2020 11:00
Azure Kinect basic capturing and visualization on Windows
/*
The most basic example to capture matching RGB and Depth images from an Azure Kinect DK device.
CImg is used to visualize the matching RGB and Depth.
*/
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "shell32.lib")
@ialhashim
ialhashim / DivergingColorMaps.hpp
Last active December 31, 2019 06:19
C++ code for a color map based on work by Kenneth Moreland
// Color map based on work by Kenneth Moreland: http://www.sandia.gov/~kmorel/documents/ColorMaps/
#pragma once
#include <QVector> // or use std::vector
inline std::vector< std::vector<double> > makeColorMap()
{
QVector<int> colorArray;
colorArray <<59<<76<<192<<60<<78<<194<<61<<80<<195<<62<<81<<197<<
63<<83<<198<<64<<85<<200<<66<<87<<201<<67<<88<<203<<68<<90<<204<<
69<<92<<206<<70<<93<<207<<71<<95<<209<<73<<97<<210<<74<<99<<211<<
from joblib import Parallel, delayed
import numpy as np
from skimage.transform import resize
files = list(data.keys())[1:]
def coords(filename):
filename = filename.replace('11_1024/', '').replace('.jpg', '').replace('11_', '')
filename = filename.replace('[','').replace(']','').split('_')