Skip to content

Instantly share code, notes, and snippets.

View jeanpat's full-sized avatar

Pommier jeanpat

View GitHub Profile
@jeanpat
jeanpat / anisotropy_RoseDirections.py
Created November 27, 2013 09:23
This python code implements the morphological "rose des directions" operator, based on morphological erosion. readmagick is used to load an image, another lib could be used.
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 7 15:19:19 2011
@author: Jean-Patrick Pommier
http://www.dip4fish.blogspot.com
"""
from __future__ import division
import numpy as np
from scipy import ndimage as nd
@jeanpat
jeanpat / anisotropy.ipynb
Created November 27, 2013 10:53
Ipython notebook analysing anisotropy of a segmented object (chromosome image) by successive erosion
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jeanpat
jeanpat / extractParticles.ipynb
Created January 29, 2014 14:13
Image segmentation can be performed by an image labelling process. Once segmented, it could necessary to isolate in independant images the labelled regions. Think of chromosomes in a metaphase image, if resolving chromosomes overlapps or karyotyping must be performed. The following script takes "two images", (in fact two small numpy arrays:img i…
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jeanpat
jeanpat / extractParticles.py
Last active August 29, 2015 13:56
A python function relying on scipy.ndimage to extract region of interest in an image or in a stack of images with a a label image, spurious pixels are removed.
def extractParticles(greyIm, LabIm):
locations = nd.find_objects(LabIm)
i=1
extracted_images=[]
for loc in locations:
lab_image = np.copy(LabIm[loc])
grey_image = np.copy(greyIm[loc])
lab_image[lab_image<>i]=0
grey_image[lab_image <>i]=0
extracted_images.append(grey_image)
@jeanpat
jeanpat / chromosomes extraction from mfish image.ipynb
Last active August 29, 2015 13:56
This ipython notebook shows how to extract, with scipy.ndimage, chromosomes from a set of mfish images.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jeanpat
jeanpat / resizeImages.py
Created February 21, 2014 15:20
Given a list of monochrome images or multispectral images (example rgb, or also a z-stack of images) build a list of images of the same size by adding borders.
def ResizeImages(ImList):
'''Find the largest width and height of images belonging to a list.
Return a list of images of same width/height
'''
maxwidth=0
maxheight=0
if len(np.shape(ImList[0]))==3:
components = np.shape(ImList[0])[2]
imtype = ImList[0].dtype
for i in range(len(ImList)):
@jeanpat
jeanpat / MFISH_colorCombination.ipynb
Created March 20, 2014 14:41
An ipython notebook showing how to combine five greyscaled images into one RGB MFISH image using scikit-image
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jeanpat
jeanpat / MaximalQuadrilateralFromNecklaces.ipynb
Created April 10, 2014 12:27
Here 4-tuples of points are considered. A necklace is a set of 4-tuples which can be deduced from one to an other one by circular permutations. With four points, when a maximal area quadrilateral is searched it is faster to search it in the set of the six possible necklaces than in the set of the 4!=24 possible permutations of a 4-tuple.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jeanpat
jeanpat / DrawLetters.py
Created May 30, 2014 14:48
Draw letters with Pillow using the verdana true type font
from PIL import Image, ImageDraw, ImageFont
import mahotas as mh
def makeLetterImage(character, size):
image = Image.new("RGBA", (600,150), (255,255,255))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("verdana.ttf", size)
draw.text((5, 0), character, (0,0,0), font=font)
img_resized = np.array(image.resize((300,75), Image.ANTIALIAS))
@jeanpat
jeanpat / C8skel_to_Graph.py
Created May 30, 2014 21:29
Cell of an ipython notebook containing a function to convert the image of a skeleton defined on a neighborhood of 8 pixels, into a graph (networkx). Depends on numpy, mahotas, networkx
import mahotas as mh
import networkx as nx
import numpy as np
def C8skeleton_to_graph(skeletonC8):
#images processing: extraction of branchedpoints, end-points, edges
ep = endPoints(skeletonC8)
bp = branchedPoints(skeletonC8, showSE = False)
## Label branched-points
l_bp,_ = mh.label(bp)