Giter Club home page Giter Club logo

gridfit's Introduction

gridfit

github action codecov

Simple Python library for fitting a (rectangular) grid of shapes in an image to a set of points.

Note that the current beta version still lacks a number of features.

gridfit example

Requirements

This module requires Python >= 3.8 and the following packages:

  • numpy
  • scipy
  • opencv-python
  • matplotlib

Installation

Install with pip

$ pip install git+https://github.com/nelsond/gridfit

Example usage

First, find the dominant angle of a rectangular grid in an image (uses the standard deviation of the Radon transformation).

import numpy as np
from gridfit.rect import find_dominant_angle

image = np.load('data.npy')
angle = find_dominant_angle(image)

After finding the dominant angle of the rectangular grid, we can fit Gaussian-shaped blobs to the one-dimensional projection of the data. This allows us to extract the coordinates of all points on the rectangular grid.

import matplotlib.pyplot as plt
from gridfit.rect import fit_grid

grid = fit_grid(image, angle, min_rel_height=0.2)

plt.imshow(image)
for col in grid:
    for row in col:
        plt.plot(row[1], row[0], 'ro', mfc='none', ms=10)

Once the grid has been determined, we can use a set of ROIs to analyze the data.

from gridfit.roi import CircularROI, ROIDataset

rois = []
for point in grid.reshape(-1, 2):
    roi = CircularROI(point, 15)
    rois.append(roi)

ds = ROIDataset(image, rois)
ds.plot(show_center=False, imshow_kwargs=dict(cmap=plt.cm.Greys_r))

# determine sum across each ROI on the grid
summed = ds.sum().reshape(*grid.shape[:2], -1)

# determine centroid in each ROI (first moment)
centroids = ds.centroid(absolute=True).reshape(*grid.shape[:2], -1)

# determine rms size in each ROI (square root of the second moment)
rms_size = ds.rms_size().reshape(*grid.shape[:2], -1)

Development

Install requirements for development environment

$ pip install .[dev]

Run tests

$ pytest tests/

Generate coverage report

$ pytest --cov=gridfit --cov-report html tests/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.