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

# Set model color
window.set_model_color("bone_model", (1.0, 0.0, 0.0))

# 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.25.tar.gz (9.2 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.25-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: medscope-0.1.25.tar.gz
  • Upload date:
  • Size: 9.2 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.25.tar.gz
Algorithm Hash digest
SHA256 2577bdf2f2c96c3bd0927c5c5b36b72c02459b4f4ce11aaca917089746d329b6
MD5 381af308ed2819b5ef0e8b2cab84e3f7
BLAKE2b-256 0b9be065c629e3204d58ff2944253db91e07744db662498cac40d192f3bf0772

See more details on using hashes here.

File details

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

File metadata

  • Download URL: medscope-0.1.25-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.25-py3-none-any.whl
Algorithm Hash digest
SHA256 78116837f69502b7d1f5901bb253585bafe1b1612abbcf3742e5ab8dd39cceb7
MD5 5e43d6f1dffb9c4c075533c4a91e8957
BLAKE2b-256 b92b9e178fded5a8a793bccfe98f6eb68e330a26ce3a13b40dc0ba1f8bd34a10

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