Posts

Random thoughts or tips

Access Azure Virtual Desktop (AVD) from Linux

Azure Virtual Desktop (AVD), formerly Windows Virtual Desktop (WVD) is a desktop-as-a-service (DaaS) offered by Microsoft. It can serve as a safe alternative to using virtual private network (VPN) on a personal device. Both Windows and macOS have official native clients for AVD/WVD. Currently, there is no official clients on Linux. AVD uses rdpw files which cannot be used on popular Linux RDP clients such as Remmina. Thankfully, the latest FreeRDP now supports authenticating to AVD.

March 26, 2025

A few simple scripts for automated data backup

PowerShell on Windows work computer Work computers within the hospital network typically restrict administrative rights to install custom tools. Over the years, I have found that PowerShell + robocopy nightly backup to an intranet network share is the most straight-forward method. First create the following PowerShell script and save it as nightly-backup.ps1 under User Home. ROBOCOPY C:\Workspace \INTRANET\UserHome\Backup\Workspace /DCOPY:DA /MT /MIR /FFT /Z /XA:SH /R:0 /TEE /XJD Then create a task in Task Scheduler to be run every midnight.

October 12, 2019

Compile VTK 8.2.0 with Visual Studio 2019

The Visualization Toolkit (VTK) is the 3D engine behind many scientific visualization applications, such as MayaVi, the popular scientific data visualizer for Python. It is also the cornerstone of several advanced 3D-enabled biomedical applications, such as ParaView and 3D Slicer. Perhaps lesser known, VTK provides a built-in high performance DICOM parser, because of its deep roots within the biomedical community. For my own clinical project, I have recently started learning and using VTK.

May 29, 2019

Modify multiple elements of a Numpy ndarray with ravel_multi_index

Indexing a multi-dimensional Numpy array Accessing a multi-dimensional Numpy array by indices is useful for many tasks, such as parsing the contours in a DICOM-RTSTRUCT file. As a simple example, we are given a 5 x 6 array arr, and a list of the coordinates of 3 points coords: >>> import numpy as np >>> arr = np.arange(30).reshape(5,6) >>> coords = np.array([[0, 1], [3, 4], [3, 2]]) >>> arr array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29]]) >>> coords array([[0, 1], [3, 4], [3, 2]]) To obtain the values of the targeted pixels as a list [arr[0,1], arr[3,4], arr[3,2]], that is [1, 22, 20], it is tempting to write “arr[coords]”.

April 15, 2019

Parse DICOM RTSTRUCT (Radiotherapy Structure Set) into binary masks using Numpy

DICOM-RTSTRUCT Contour Data Contours drawn for radiotherapy are saved as DICOM RT Structure Set (“RT” stands for radiotherapy.) in DICOM Standard, and usually as a single file. You can locate this file among CT or MRI data sets quite reliably, by traversing recursively through the directories and looking for MODALITY of “RTSTRUCT”. In this modality, the contours are saved as 2D polygons slice by slice under the Contour Data (3006,0050) tag, which species the data format as:

March 9, 2019