Skip to main content

A package that creats quadtree mesh from an image

Project description

Contributors Forks Stargazers Issues MIT License LinkedIn Made with love in SUT (Iran)


Logo

QTREEMESH

Generation of QuadTree mesh from an image
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

QTREEMESH is a python package that can create a Quadtree structure from an image. This tree data structure can also be converted to mesh structure that can be used in different areas of science, e.g. finite element analysis. The Quadtree algorithm in this package is based on pixels' intensity.

(back to top)

Built With

python

(back to top)

Getting Started

This part explains how to install and use this package.

Installation

Install QTREEMESH from PyPI via pip.

pip install qtreemesh

(back to top)

Usage

There is a test.py file in examples folder that demonstrate how different parts of this package work. Here we go through this file line by line:

1. Read image

First we import required tools from other libraries

from PIL import Image # to read image file properly
from numpy import asarray # for converting image matrix to array

Then we read the image and convert it to gray-scale. There are three example images in examples folder. 4.jpg is smaller than the two others and need fewer computation efforts.

im = Image.open("4.jpg").convert('L')

2. Preprocessing

In order to implement QuadTree algorithm, the image should be square and the number of pixels in each dimension should be of order $2^n$ (more explanation to be added). There is a function image_preprocess dedicated to this modification of original image:

from qtreemesh import image_preprocess

imar = image_preprocess(asarray(im))

3. QuadTree Algorithm

The QuadTree decomposition can be performed on image_array using a recursive class QTree based on given tolerance.

from qtreemesh import QTree

quad = QTree(None, imar, 125) # QTree(None, image_array, tolerance)

QTree object may have 4 children QTree objects (can be accessed through attributes: north_west, north_east, south_west, south_east) and so on. Each QTree has an attribute divided that determines the existence of children partitions. There are also an property method for counting count_leaves and a method for saving tree leaves save_leaves (i.e. undivided partitions).

4. Mesh Generation

Common mesh data structure can be extracted from QuadTree structure using QTreeMesh class. After initiating the class, corresponding elements and nodes can be generated as attributes of the QTreeMesh object with the method create_elements. The resulted mesh may be illustrated using draw method.

from qtreemesh import QTreeMesh

mesh = QTreeMesh(quad)
mesh.create_elements()
mesh.draw(True, 'orangered') # mesh.draw(fill_inside, edge_color, save_name)

Each element in elements is a QTreeElement object that contains many attributes, e.g. element number : number, element nodes : nodes_numbers, element property (average of pixel intensities) : element_property and etc.

Example Image Mesh
4.jpg image 4 image 4 meshed
5.jpg image 5 image 5 meshed

For more examples, please refer to the Documentation

(back to top)

Roadmap

  • Completing the codes documentation
  • Adding details to README file
  • Exporting data as vtk format
  • Successfully implement in FEM software
    • Handling hanging nodes
    • Prepare required data
    • Illustrate usage in open-source FEM programs
  • Prepare required data for SBFEM

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Sadjad Abedi - AbediSadjad@gmail.com

Project Link: https://github.com/Sad-Abd/qtreemesh

(back to top)

Acknowledgments

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtreemesh-0.1.1.tar.gz (13.4 kB view hashes)

Uploaded Source

Built Distribution

qtreemesh-0.1.1-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page