Coder Social home page Coder Social logo

raster_geometry's Introduction

Raster Geometry

Raster Geometry - Create/manipulate N-dim raster geometric shapes.

Overview

This software provides a library for generating or otherwise manipulating N-dimensional raster geometric shapes.

Most of the code is used is used in a number of projects where it is tested against real-life scenarios.

As a result of the code maturity, some of the library components may undergo (eventually heavy) refactoring. While this is not expected, this will be documented. Please file a bug report if you detect an undocumented refactoring.

Releases information are available through NEWS.rst.

For a more comprehensive list of changes see CHANGELOG.rst (automatically generated from the version control system).

Features

The 2D geometrical shapes currently available are:

  • square
  • rectangle
  • rhombus
  • circle
  • ellipse

The 3D geometrical shapes currently available are:

  • cube
  • cuboid
  • rhomboid
  • sphere
  • ellipsoid
  • cylinder

The N-dim geometrical shapes currently available are:

  • cuboid: sum[abs(x_n/a_n)^inf] < 1
  • superellipsoid: sum[abs(x_n/a_n)^k] < 1
  • prism: stack (N-1)-D rendered objects on given axis

etc.

Additional may be added in the future.

Installation

The recommended way of installing the software is through PyPI:

$ pip install raster_geometry

Alternatively, you can clone the source repository from GitHub:

$ git clone [email protected]:norok2/raster_geometry.git
$ cd raster_geometry
$ pip install -e .

For more details see also INSTALL.rst.

License

This work is licensed through the terms and conditions of the GPLv3+ See the accompanying LICENSE.rst for more details.

Acknowledgements

For a complete list of authors please see AUTHORS.rst.

People who have influenced this work are acknowledged in THANKS.rst.

raster_geometry's People

Contributors

norok2 avatar adnanavdagic avatar

Stargazers

 avatar Wenxuan Guo avatar  avatar Christian Karcher avatar Arkadiusz Choruży avatar  avatar Ashkan Pakzad avatar 梁植华 avatar  avatar Mathilde Bateson avatar  avatar Gorka Muñoz avatar  avatar Qian Cao avatar Max Brambach avatar Chris Byrohl avatar  avatar R. M. Sandu avatar Cenbylin avatar Kosuke Takeuchi avatar R. Patrick Xian avatar  avatar Roman Solovyev avatar

Watchers

James Cloos avatar  avatar

raster_geometry's Issues

Computation time increases rapidly with increasing shape size

Thank you very much for your hard work developing this very useful library!

I was curious if you have any thoughts or suggestions for speeding up computation time for generating large shapes (specifically using nd_superellipsoid()). I have noticed that as the array shape increases, the computation time dramatically increases as well.

%time rg.nd_superellipsoid((5,5,5), 2, rel_sizes=False).astype(np.int_)
%time rg.nd_superellipsoid((50,50,50), 2, rel_sizes=False).astype(np.int_)
%time rg.nd_superellipsoid((500,500,500), 2, rel_sizes=False).astype(np.int_)
%time rg.nd_superellipsoid((1000,1000,1000), 2, rel_sizes=False).astype(np.int_)

CPU times: user 298 µs, sys: 343 µs, total: 641 µs
Wall time: 4.31 ms
CPU times: user 1.24 ms, sys: 1.43 ms, total: 2.67 ms
Wall time: 5.05 ms
CPU times: user 275 ms, sys: 375 ms, total: 650 ms
Wall time: 650 ms
CPU times: user 1.98 s, sys: 2.95 s, total: 4.93 s
Wall time: 4.94 s

I have been struggling for a while to try to come up with a solution, however I have been unsuccessful so far. Do you believe there can be a way to possibly speed up this calculation? Thank you in advance!

raster_geometry.sphere is giving different volumes when only the position changes

Hi All,

I have a set of midpoints (from labelled tumours within a set of scans [512x512x512 voxels]). I'm just trying to create a sphere with a radius of 10 voxels at each midpoint. To do this, I'm using raster_geometry.sphere and defining the position as the midpoint/512 (i.e. position = midpoint/ 512 , raster_geometry.sphere(512, 10, positon) )

When I'm doing this, however, the volume of the sphere changes. Is there something I don't understand about raster_geometry?

from logzero import logger as logging
from lama import common
import numpy as np
import SimpleITK as sitk
import raster_geometry as rg

for i, img_path in enumerate(scan_paths):
    logging.info(img_path)
    logging.info(tumour_paths[i])

    m_loader = common.LoadImage(tumour_paths[i])
    mask = m_loader.img

    m_array = sitk.GetArrayFromImage(mask)

    s = ndimage.find_objects(m_array)[-1]

    midpoint = [(np.mean([s[0].start, s[0].stop]))/512,
                (np.mean([s[1].start, s[1].stop]))/512,
                (np.mean([s[2].start, s[2].stop]))/512]

    print("Original Midpoint", [i*512 for i in midpoint])

    print("Modified midpoint", midpoint)

    arr = rg.sphere(512, 10, midpoint).astype(np.int_)

    print(np.count_nonzero(arr))
    print(np.sum(arr))

Example Output:

[I 220525 17:37:58 radiomics_normaliser:86] E:\220204_BQ_dataset\220521_BQ_norm\imgs\200721_MPTLVo3_GFSeeds_4T1R_4T1R_D7_C1_002.nrrd
[I 220525 17:37:58 radiomics_normaliser:87] E:\220204_BQ_dataset\220521_BQ_norm\tumour_respaced\200721_MPTLVo3_GFSeeds_4T1R_4T1R_D7_C1_002.nrrd
Original Midpoint [260.5, 252.5, 162.0]
Modified midpoint [0.5087890625, 0.4931640625, 0.31640625]
4160
4160
[I 220525 17:38:14 radiomics_normaliser:86] E:\220204_BQ_dataset\220521_BQ_norm\imgs\200721_MPTLVo3_GFseeds_4T1R_4T1R_D7_C1_003.nrrd
[I 220525 17:38:14 radiomics_normaliser:87] E:\220204_BQ_dataset\220521_BQ_norm\tumour_respaced\200721_MPTLVo3_GFseeds_4T1R_4T1R_D7_C1_003.nrrd
Original Midpoint [219.5, 234.5, 165.5]
Modified midpoint [0.4287109375, 0.4580078125, 0.3232421875]
4165
4165

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.