Skip to main content

Medical Intraoperative Real-time Visualization System.

Project description

medscope

Medical Intraoperative Real-time Visualization System.

Demo

[!TIP] For another demo, see https://github.com/GGN-2015/medscope_demo_project

Installation

[!IMPORTANT] You should use python >=3.10, <3.13

pip install medscope

Usage

[!WARNING] Do not use multithreading, use MedScopeWindow.add_timer

from medscope import MedScopeWindow, MedScopeSystem
import numpy as np
import sys

# Generate a random 3x3 rotation matrix uniformly distributed over SO(3).
def random_rotation_matrix() -> np.ndarray:
    phi = np.random.uniform(0, 2 * np.pi)
    theta = np.random.uniform(0, np.pi)
    psi = np.random.uniform(0, 2 * np.pi)
    cos_phi, sin_phi = np.cos(phi), np.sin(phi)
    cos_theta, sin_theta = np.cos(theta), np.sin(theta)
    cos_psi, sin_psi = np.cos(psi), np.sin(psi)
    R = np.array([
        [cos_phi*cos_theta*cos_psi - sin_phi*sin_psi, 
         -cos_phi*cos_theta*sin_psi - sin_phi*cos_psi, 
         cos_phi*sin_theta],
        [sin_phi*cos_theta*cos_psi + cos_phi*sin_psi, 
         -sin_phi*cos_theta*sin_psi + cos_phi*cos_psi, 
         sin_phi*sin_theta],
        [-sin_theta*cos_psi, 
         sin_theta*sin_psi, 
         cos_theta]
    ])
    
    return R

# Initialize app and window
app = MedScopeSystem(sys.argv)
window = MedScopeWindow()

# Add a 3D model
window.add_model_from_file(
    "bone_model",
    "BONE-1.real.stl",
    (1.0, 1.0, 1.0))  # white, random if not given

# Check intersection (True)
print(window.check_model_intersect("bone_model", "bone_model"))

# Set the pose of camera
#   you can change camera pos in callback function with add_timer
window.set_camera_pose(
    (0, 0, -500),
    (0, 0, 0),
    (0, 1, 0)
)

# Volume data should be given in 3D np.ndarray 
#   and dtype should be np.uint8
#   RGB channel image 3 * N * M * L
# window.set_volume(np.random.randint(0, 255, (3, 256, 256, 256)).astype(np.uint8))

# use N * M * L to achieve grey image
window.set_volume(np.random.randint(0, 255, (256, 256, 256)).astype(np.uint8))

# calculate every 1.0s
import time
lp = time.time()
pp = 1.0

# Create a callback function to move your model
def move_model():
    import random
    global lp
    if time.time() - lp >= pp:
        lp = time.time()
        x = random.random() * 256
        y = random.random() * 256
        z = random.random() * 256
        window.set_slice_positions(x, y, z)
        window.set_model_pose(
            "bone_model",
            (x  - 128, y - 128, z - 128),
            random_rotation_matrix()
        )

# Call move_model every 1ms (as quickly as the processor can)
window.add_timer("move_model", 1, move_model)
sys.exit(app.exec_())

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

medscope-0.1.24.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

medscope-0.1.24-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file medscope-0.1.24.tar.gz.

File metadata

  • Download URL: medscope-0.1.24.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.12 Windows/11

File hashes

Hashes for medscope-0.1.24.tar.gz
Algorithm Hash digest
SHA256 ebae5fdd1998311653cb0e4dc0173878db92688517d3d90979666f1bb97212ee
MD5 7c29464f3a7c86a649a4ff47da771db8
BLAKE2b-256 e2ae77108e5b8beaa5fe4aabc69005b72743707a10887fe3d382fbea7c9c981c

See more details on using hashes here.

File details

Details for the file medscope-0.1.24-py3-none-any.whl.

File metadata

  • Download URL: medscope-0.1.24-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.12 Windows/11

File hashes

Hashes for medscope-0.1.24-py3-none-any.whl
Algorithm Hash digest
SHA256 3fef98107b45903574849858e5a7bd4e09d0471bf94aead348dc45d269cb93c4
MD5 306ce8f4ba4412995fd3527b8d1ecc0f
BLAKE2b-256 28560401981c646d8e925d2cbb05498dd0c2868f64589d3596c9f6d7dcfec1a5

See more details on using hashes here.

Supported by

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