{"@attributes":{"version":"2.0"},"channel":{"title":"Jun Kwan","link":"https:\/\/junwenkwan.github.io\/","description":"Recent content on Jun Kwan","generator":"Hugo -- 0.147.2","language":"en-us","lastBuildDate":"Thu, 26 Nov 2026 00:00:00 +0000","item":[{"title":"Understanding DICOM","link":"https:\/\/junwenkwan.github.io\/posts\/understanding-dicom\/","pubDate":"Thu, 26 Nov 2026 00:00:00 +0000","guid":"https:\/\/junwenkwan.github.io\/posts\/understanding-dicom\/","description":"<p>Digital Imaging and Communications in Medicine (DICOM) is the international standard for medical imaging information and related data. It defines the formats for medical images used in clinical practice.<\/p>\n<p>The <a href=\"https:\/\/www.magnetomworld.siemens-healthineers.com\/korean-dicom-image-gallery\">T2 TSE tra<\/a> example from the Siemens Healthineers gallery contains 21 MR frames in a single file. The examples use pydicom and NumPy and expect <code>IMG-0001-00001.dcm<\/code> in the current directory.<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">import<\/span> numpy <span style=\"color:#66d9ef\">as<\/span> np\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> pydicom <span style=\"color:#f92672\">import<\/span> dcmread\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> pydicom.pixels <span style=\"color:#f92672\">import<\/span> pixel_array\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>path <span style=\"color:#f92672\">=<\/span> <span style=\"color:#e6db74\">&#34;IMG-0001-00001.dcm&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>ds <span style=\"color:#f92672\">=<\/span> dcmread(path, stop_before_pixels<span style=\"color:#f92672\">=<\/span><span style=\"color:#66d9ef\">True<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#75715e\"># Read the image and scanner metadata.<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(ds<span style=\"color:#f92672\">.<\/span>SOPClassUID<span style=\"color:#f92672\">.<\/span>name) <span style=\"color:#75715e\"># Enhanced MR Image Storage<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(ds<span style=\"color:#f92672\">.<\/span>NumberOfFrames, ds<span style=\"color:#f92672\">.<\/span>Rows, ds<span style=\"color:#f92672\">.<\/span>Columns) <span style=\"color:#75715e\"># 21 frames, 896 rows, 732 columns<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(ds<span style=\"color:#f92672\">.<\/span>Modality) <span style=\"color:#75715e\"># MR<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(ds<span style=\"color:#f92672\">.<\/span>get(<span style=\"color:#e6db74\">&#34;ManufacturerModelName&#34;<\/span>)) <span style=\"color:#75715e\"># MAGNETOM Vida<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(ds<span style=\"color:#f92672\">.<\/span>get(<span style=\"color:#e6db74\">&#34;MagneticFieldStrength&#34;<\/span>)) <span style=\"color:#75715e\"># 3 tesla<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(ds<span style=\"color:#f92672\">.<\/span>file_meta<span style=\"color:#f92672\">.<\/span>TransferSyntaxUID<span style=\"color:#f92672\">.<\/span>name) <span style=\"color:#75715e\"># Explicit VR Little Endian<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#75715e\"># (0028,0010) is the DICOM tag for Rows. US means unsigned 16-bit integer.<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>rows <span style=\"color:#f92672\">=<\/span> ds[<span style=\"color:#ae81ff\">0x0028<\/span>, <span style=\"color:#ae81ff\">0x0010<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span>print(rows<span style=\"color:#f92672\">.<\/span>tag, rows<span style=\"color:#f92672\">.<\/span>VR, rows<span style=\"color:#f92672\">.<\/span>value) <span style=\"color:#75715e\"># (0028,0010) US 896, meaning 896 rows<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#75715e\"># Enhanced MR stores pixel spacing and display settings per frame.<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>frame_info <span style=\"color:#f92672\">=<\/span> ds<span style=\"color:#f92672\">.<\/span>PerFrameFunctionalGroupsSequence[<span style=\"color:#ae81ff\">0<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span>measures <span style=\"color:#f92672\">=<\/span> frame_info<span style=\"color:#f92672\">.<\/span>PixelMeasuresSequence[<span style=\"color:#ae81ff\">0<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span>window <span style=\"color:#f92672\">=<\/span> frame_info<span style=\"color:#f92672\">.<\/span>FrameVOILUTSequence[<span style=\"color:#ae81ff\">0<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#75715e\"># Pixel spacing measures the distance between adjacent pixel centres.<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(measures<span style=\"color:#f92672\">.<\/span>PixelSpacing) <span style=\"color:#75715e\"># 0.2567 mm between rows and between columns<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#75715e\"># The window maps a range of intensities to shades of grey.<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(window<span style=\"color:#f92672\">.<\/span>WindowCenter, window<span style=\"color:#f92672\">.<\/span>WindowWidth) <span style=\"color:#75715e\"># centre 517, width 1102<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#75715e\"># Decode nine frames spread across the scan.<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>indices <span style=\"color:#f92672\">=<\/span> np<span style=\"color:#f92672\">.<\/span>linspace(<span style=\"color:#ae81ff\">0<\/span>, int(ds<span style=\"color:#f92672\">.<\/span>NumberOfFrames) <span style=\"color:#f92672\">-<\/span> <span style=\"color:#ae81ff\">1<\/span>, <span style=\"color:#ae81ff\">9<\/span>, dtype<span style=\"color:#f92672\">=<\/span>int)\n<\/span><\/span><span style=\"display:flex;\"><span>frames <span style=\"color:#f92672\">=<\/span> [pixel_array(path, index<span style=\"color:#f92672\">=<\/span>int(index)) <span style=\"color:#66d9ef\">for<\/span> index <span style=\"color:#f92672\">in<\/span> indices]\n<\/span><\/span><span style=\"display:flex;\"><span>print(len(frames), <span style=\"color:#f92672\">*<\/span>frames[<span style=\"color:#ae81ff\">0<\/span>]<span style=\"color:#f92672\">.<\/span>shape) <span style=\"color:#75715e\"># 9 frames, 896 rows, 732 columns<\/span>\n<\/span><\/span><\/code><\/pre><\/div><figure class=\"align-center\">\n<img src=\"https:\/\/junwenkwan.github.io\/images\/understanding-dicom\/frame-grid.png#center\" alt=\"Nine axial MR frames arranged in a labelled 3 by 3 grid\" width=\"656\" height=\"881\" style=\"height: auto\" loading=\"lazy\">\n<figcaption><p>Nine frames sampled across the 21-frame scan. Each uses its stored display window.<\/p>"},{"title":"GPU Acceleration with the C++ Standard Libray","link":"https:\/\/junwenkwan.github.io\/posts\/nvidia-gpu-acceleration\/","pubDate":"Mon, 09 Mar 2026 00:00:00 +0000","guid":"https:\/\/junwenkwan.github.io\/posts\/nvidia-gpu-acceleration\/","description":"<p>DAXPY updates each element of a vector independently. We&rsquo;ll turn a CPU loop into a standard C++ algorithm, run it on an NVIDIA GPU, and compare the effective bandwidth.<\/p>\n<ol class=\"daxpy-flow\" role=\"list\" aria-label=\"DAXPY implementation stages\">\n<li>\n<strong>CPU loop<\/strong>\n<code>y[i] += a * x[i]<\/code>\n<\/li>\n<li>\n<strong>Sequential algorithm<\/strong>\n<code>transform(seq)<\/code>\n<\/li>\n<li>\n<strong>GPU offload<\/strong>\n<code>transform(par_unseq)<\/code>\n<code>nvc++ -stdpar=gpu<\/code>\n<\/li>\n<\/ol>\n<p>This walkthrough is based on a <a href=\"https:\/\/learn.nvidia.com\/courses\/course-detail?course_id=course-v1:DLI+S-AC-08+V1\">self-paced course from NVIDIA&rsquo;s Deep Learning Institute<\/a>.<\/p>\n<h2 id=\"daxpy-as-a-bandwidth-benchmark\">DAXPY as a Bandwidth Benchmark<\/h2>\n<p>DAXPY stands for <strong>D<\/strong>ouble-precision <strong>A<\/strong>X <strong>P<\/strong>lus <strong>Y<\/strong>, and it computes the following equation.<\/p>"},{"title":"Model Context Protocol","link":"https:\/\/junwenkwan.github.io\/posts\/model-context-protocol\/","pubDate":"Wed, 04 Jun 2025 00:00:00 +0000","guid":"https:\/\/junwenkwan.github.io\/posts\/model-context-protocol\/","description":"<p>Model Context Protocol (MCP) is an open source standard for LLMs to be interacting with applications. MCP is originally introduced by Anthropic <a href=\"https:\/\/www.anthropic.com\/news\/model-context-protocol\">in this post<\/a>. With MCP, LLMs now can have assess to custom tools or data source to provide a more intelligent response.<\/p>\n<p>In addition, MCP also allows developers to build agents capable of more tasks, such as searching the internet or exploring dataset. MCP essentially standardizes LLM applications to work with many toolings. A nice quote by an Anthropic developer, &ldquo;the models are only as good as the context provided to them&rdquo;.<\/p>"},{"title":"About","link":"https:\/\/junwenkwan.github.io\/about\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/junwenkwan.github.io\/about\/","description":"<p>Hi, I\u2019m Jun Kwan, and I live in Melbourne, Australia \ud83c\udde6\ud83c\uddfa.<\/p>\n<p>I work as a Machine Learning Engineer with around six years of experience building scalable ML systems for enterprise applications. I\u2019m deeply passionate about advancing the field of machine learning, with particular interests in computer vision and robotics. I\u2019m proficient in Python and C++, and have applied them extensively across production systems and research projects.<\/p>\n<p>Before entering the industry, I studied at Monash University, where I earned a Bachelor of Engineering (Honours) degree in Electrical and Computer Systems Engineering.<\/p>"}]}}