Skip to content

Instantly share code, notes, and snippets.

View prerakmody's full-sized avatar
🏠
Working from home

pmod prerakmody

🏠
Working from home
View GitHub Profile
@prerakmody
prerakmody / camelyon16.py
Created November 24, 2022 13:08
Histopathology Image Reading
"""
CAMELYON 16 DATASET
- Whole Slide Images (WSI) containing histopathological information on breast cancer
1. Download
- To view the list of AWS
- Link: https://aws.amazon.com/marketplace/pp/prodview-exkvqrznup6vc?sr=0-1&ref_=beagle&applicationId=AWSMPContessa#resources
- Click on Resources on AWS --> View Resources
- Single Sample
- aws s3 cp --no-sign-request s3://camelyon-dataset/CAMELYON16/images/tumor_032.tif ./raw/tumor_032.tif
@prerakmody
prerakmody / loadCTInCornerstone.html
Created January 24, 2024 10:51
Cornerstone.js for loading a folder of .dcm files
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<script src="https://unpkg.com/cornerstone-core/dist/cornerstone.js"></script> <!-- cornerstone-core - 2.6.1 - 2021-11-19 -->
<script src="https://unpkg.com/cornerstone-tools/dist/cornerstoneTools.js"></script> <!-- cornerstone-tools - 6.0.10 - 2023-07-21 -->
<script src="https://unpkg.com/cornerstone-math/dist/cornerstoneMath.js"></script> <!-- cornerstone-math - 0.1.10 - 2022-06-09 -->
import os
import numpy as np
from sklearn.metrics import log_loss
"""
- HARDCODED FORMULAE
- In this gist, we shall almost always use probabilities and not unscaled logits
"""
## BINARY CLASS CROSS ENTROPY
y_true = [0,0,0,1] # 4 observations
@prerakmody
prerakmody / ct-rtdose-plot.py
Last active October 8, 2023 01:53
DICOM (CT and RTDOSE) mapping in matplotlib
"""
Step 1 - Read Dose and CT .dcm files
Step 2 - Resample dose to CT
Step 3 - Plot
"""
import pdb
import pydicom
import traceback
import numpy as np
import SimpleITK as sitk
@prerakmody
prerakmody / conversion.py
Last active July 19, 2023 00:09
Simple ITK (SITK) + ITK hacks (python)
import itk
import SimpleITK as sitk
def convert_sitk_to_itk(sitk_img):
img_array = sitk.GetArrayFromImage(sitk_img)
itk_img = itk.GetImageFromArray(img_array)
itk_img.SetOrigin(tuple(sitk_img.GetOrigin()))
itk_img.SetSpacing(tuple(sitk_img.GetSpacing()))
itk_img.SetDirection(itk.GetMatrixFromArray(np.reshape(np.array(sitk_img.GetDirection()), [sitk_img.GetDimension()]*2)))
@prerakmody
prerakmody / ASAP-CentOS.md
Last active July 16, 2023 21:27
ASAP Installation (Whole Slide Images in Digital Pathology)

Install ASAP on CentOS Stream (within a conda environment as a non-root user)

Preliminary points

  1. The approach here is to first build/install dependencies of ASAP and then define their paths in the cmake command for ASAP. The order in which I build the dependencies is in the same order as defined using the find_package() function in ASAP/CMakeLists.txt.
  2. Assumptions
    • Note 1: I assume you have your conda environment installed and activated
    • Note 2: These instruction assume you have cmake installed. Find a basic tutorial here and a quick intuition here.
  • Note 3: These instruction also assume that you gcc --version is &gt;=9 since otherwise it leads to issues with compiling #include in some .cpp files like [core/filetools.cpp](https://github.com/computationalpatholo
@prerakmody
prerakmody / copyPlan.py
Last active July 13, 2023 09:12
Raystation - Dual Arc Beam
import connect
RS_CHECK_PREFIX = '_'
RS_STR_TRANSLATE_OBJ = { ord(' ') : ord('_') , ord('(') : ord('_') , ord(')') : ord('_') , ord('-') : ord('_') , ord('+') : ord('_') , ord('<') : ord('_') , ord('>') : ord('_') }
KEYNAME_PATIENT = 'Patient'
def checkForRTPlan(case, planName):
exists = False
if RS_CHECK_PREFIX + str(planName).translate(RS_STR_TRANSLATE_OBJ) in dir(case.TreatmentPlans):
exists = True
@prerakmody
prerakmody / README.md
Last active June 14, 2023 10:07
Functions to read rosbag files

Installation

  1. Windows (ros-noetic with pytorch)
    conda create -y -n XOSight-Pattern2 "python=3.8" "mamba>=0.22.1" -c conda-forge
    conda activate XOSight-Pattern2
    mamba install ros-noetic-desktop -c robostack -c robostack-experimental -c conda-forge --override-channels
    mamba install vs2019_win-64
    conda deactivate
    conda activate XOSight-Pattern2
    

mamba install rosdep

@prerakmody
prerakmody / memory.py
Last active February 5, 2023 17:49
Python and Unix Commands
# Option 1
import os
from pathlib import Path
filename = Path(__file__).parts[-1]
mem = os.popen("ps aux | grep %s | awk '{sum=sum+$6}; END {print sum/1024 \" MB\"}'"% (filename)).read()
# Option 2
import os
import psutil # pip install psutil
import humanize # pip install humanize
@prerakmody
prerakmody / download_gdrive.py
Last active February 5, 2023 16:19
Download open files from GDrive
import sys, time
import requests
def download_file_from_google_drive(id, destination):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None