Skip to content

Instantly share code, notes, and snippets.

View Nico-Curti's full-sized avatar
🤓
Nerd

Nico Curti Nico-Curti

🤓
Nerd
View GitHub Profile
@Nico-Curti
Nico-Curti / grid_tiler.py
Last active May 5, 2024 12:53
Image patch-coordinates generator without interal copies
import numpy as np
from itertools import product
class GridTiler (object):
'''
Image patch generator
A simple generator class for the extraction of image
patches, given a binary mask on which evaluate the
amount of no-null pixels. The object implements the
@Nico-Curti
Nico-Curti / blur_detector.py
Last active January 30, 2023 08:43
Detector of blurring regions in images independent by any information about the blurring type. Implementation of the HiFST algorithm by Golestaneh et al.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import numpy as np
from scipy import fft
# these are used **only** for the entropy filter
from skimage.util import img_as_ubyte
from skimage.filters.rank import entropy
@Nico-Curti
Nico-Curti / np_connected_components_with_stats.py
Last active January 17, 2023 11:50
Pure numpy code for the estimation of connected components in a binary image
import numpy as np
from itertools import product
from collections import defaultdict
__author__ = ['Gianluca Carlini', 'Nico Curti']
__email__ = ['gianluca.carlini3@unibo.it', 'nico.curti2@unibo.it']
def npConnectedComponentsWithStats (img : np.ndarray) -> tuple:
'''
Evaluate the connected components (with statistics)
@Nico-Curti
Nico-Curti / lucas_kanade_optical_flow.py
Created October 25, 2022 16:31
Calculates an optical flow using the iterative Lucas-Kanade method with pyramids.
import cv2
import numpy as np
import tensorflow as tf
__all__ = ['image_pyramid', 'lucas_kanade_optical_flow']
__author__ = ['Nico Curti', 'Gianluca Carlini']
__mail__ = ['nico.curti2@unibo.it', 'gianluca.carlini3@unibo.it']
@Nico-Curti
Nico-Curti / image2graph.py
Last active July 29, 2024 07:59
Extract graph from skeleton image using OpenCV
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import numpy as np
from itertools import combinations
__author__ = ['Nico Curti', 'Gianluca Carlini']
__email__ = ['nico.curti2@unibo.it', 'gianluca.carlini3@unibo.it']
@Nico-Curti
Nico-Curti / patchifier.py
Last active June 9, 2023 07:57
Extract image patches and rebuild the global image as sklearn transformer
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations
import itertools
import numpy as np
from sklearn.base import BaseEstimator
from sklearn.base import TransformerMixin
@Nico-Curti
Nico-Curti / bweuler.py
Last active July 22, 2022 09:43
Compute the Euler Number of a binary image via OpenCV, Numpy or Tensorflow (with and without bit quads evaluation)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2 # required for cv_bweuler function
import numpy as np # required for np_bweuler function
import tensorflow as tf # required for tf_bweuler function
from functools import wraps # required for checker decorator
from scipy.signal import convolve2d # required for np_bweuler function
__author__ = ['Nico Curti', 'Gianluca Carlini']
@Nico-Curti
Nico-Curti / WSImeta.py
Created July 28, 2021 10:43
Extract metadata from WSI label image using OCR
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
import os
import argparse
import numpy as np
from glob import glob
@Nico-Curti
Nico-Curti / medical_viewer.py
Created March 15, 2021 09:13
Medical image viewer for a fast evaluation of the sample. Data type supported are Dicom and Nifti
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import cv2
import argparse
import numpy as np
from functools import partial
@Nico-Curti
Nico-Curti / macenko.cpp
Last active June 21, 2022 10:24
Color Deconvolution with the PCA-based method of Macenko et al.
// g++ macenko.cpp -O3 -std=c++17 `pkg-config opencv --cflags --libs` -o macenko
#include <iostream>
#include <opencv2/opencv.hpp>
void rgb2stains (const cv :: Mat & rgb, cv :: Mat & dst, cv :: InputArray W, double I_0)
{
cv :: Mat log = cv :: max(rgb, 1e-16);