Skip to content

Instantly share code, notes, and snippets.

View ialhashim's full-sized avatar

Ibraheem Alhashim ialhashim

View GitHub Profile
@ialhashim
ialhashim / split_predict_batches.py
Created January 15, 2023 07:30
Split images into square patches
def split_to_batches(img, trained_size=512):
img = skimage.img_as_float32(img)
direction = 'landscape'
if img.shape[0] > img.shape[1]: direction = 'portrait'
# resize into 512x[width|height]
width, height = img.shape[1], img.shape[0]
if direction == 'landscape':
new_height = trained_size
new_width = int(new_height * (width / height))
@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 / 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 / readme.md
Last active April 2, 2024 11:17
Reverse port forwarding via an AWS instance

If you want to connect to a local workstation behind a firewall you can do that by bouncing traffic off of an AWS instance.

An example would be accessing a Jupyter Lab from the outside world to a machine with no static IP or behind a firewall.

The steps are:

  1. Create a paid AWS Ubuntu instance and save the '.pem' file.
  2. Make sure the AWS instance's Security Rules allows traffic in.
  3. Test that you can connect to this instance from the outside world (e.g. python3 -m http.server or jupyter lab --ip=*) then visit the instance using its public IP.
  4. (optionally) Enable password login in /etc/ssh/sshd_config by setting PasswordAuthentication yes and sudo passwd $USER.
  5. Enable GatewayPorts yes and restart sshd. E.g. sudo nano /etc/ssh/sshd_config then sudo systemctl restart ssh.service.
@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 / firebase_storage_web.dart
Created January 8, 2020 09:48
Flutter + Firebase storage on the web, work around
// Note this is just a workaround until the offical support of web
// We would need to add these as well
//// ignore_for_file: avoid_web_libraries_in_flutter
//import 'dart:html';
//import 'package:mime/mime.dart';
//import 'package:firebase/firebase.dart' as fb;
// Some upload button is pressed
onPressed: () async {
@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 / drawPointCloud.py
Last active July 18, 2023 20:56
Quick python script to draw a dynamic point cloud with changing colors and positions (e.g. RGBD frames)
from OpenGL import GL, GLU
from OpenGL.arrays import vbo
# Prepare point cloud once
def makeCloud(self):
width, height = self.rgb.shape[1], self.rgb.shape[0]
# ...
# Compute 3D positions from depth
# ...
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('_')
@ialhashim
ialhashim / fill_depth_colorization.py
Last active September 5, 2024 05:27
Python implementation of depth filling from NYU Depth v2 toolbox
# Original Matlab code https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html
#
#
# Python port of depth filling code from NYU toolbox
# Speed needs to be improved
#
# Uses 'pypardiso' solver
#
import scipy
import skimage