Skip to main content

Medical Intraoperative Real-time Visualization System.

Project description

medscope

Medical Intraoperative Real-time Visualization System.

Demo

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.new.stl",
    (1.0, 1.0, 1.0))  # white, random if not given

# 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 fps every 3.0s
import time
lp = time.time()
pp = 3.0
fc = 0

# Create a callback function to move your model
def move_model():
    global fc
    global lp
    import random
    x = random.random() * 256
    y = random.random() * 256 - 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()
    )
    fc += 1
    if time.time() - lp >= pp:
        print(f"fps: {fc / (time.time() - lp)}")
        lp = time.time()
        fc = 0


# 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.18.tar.gz (7.9 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.18-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: medscope-0.1.18.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.10.20 Windows/10

File hashes

Hashes for medscope-0.1.18.tar.gz
Algorithm Hash digest
SHA256 818b6fe9bd33df8d6a51b537e96b809988fd86f5e94c789d83017e964c6e308b
MD5 b3aa2e4506fba7154ebc9ac61bd14b9a
BLAKE2b-256 67b8e05f7ac9cd699d91f3a426b397d0cbb955afe36fdd0da8f51bb12f77e06e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: medscope-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.10.20 Windows/10

File hashes

Hashes for medscope-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 de0515c61c506e400cf3a04960dc45fdc8df6229495abe63ed5e8984e9477579
MD5 475a4fa9e815693475ede1c2e9fbdad9
BLAKE2b-256 e7841803b800abfb82f5a52248f4d1c8cf1aa9368f5befd7a454c2a41d98ea30

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