<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Farhatbasir on Medium]]></title>
        <description><![CDATA[Stories by Farhatbasir on Medium]]></description>
        <link>https://medium.com/@farhatbasir02?source=rss-17f60c44d60d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*T9XysDoRgBKGsbA8</url>
            <title>Stories by Farhatbasir on Medium</title>
            <link>https://medium.com/@farhatbasir02?source=rss-17f60c44d60d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:36:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@farhatbasir02/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Build End-to-End Pipelines for ECG, DICOM, and Echocardiography Data in Python]]></title>
            <link>https://medium.com/@farhatbasir02/how-i-build-end-to-end-pipelines-for-ecg-dicom-and-echocardiography-data-in-python-cd8b886dbef8?source=rss-17f60c44d60d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd8b886dbef8</guid>
            <category><![CDATA[biomedical-engineering]]></category>
            <category><![CDATA[freelancer-blogs]]></category>
            <category><![CDATA[upwork-freelancing]]></category>
            <category><![CDATA[matlab-assignment-help]]></category>
            <category><![CDATA[medical-imaging]]></category>
            <dc:creator><![CDATA[Farhatbasir]]></dc:creator>
            <pubDate>Mon, 15 Jun 2026 11:04:32 GMT</pubDate>
            <atom:updated>2026-06-15T11:04:32.248Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Farhat Basir — Biomedical Engineer | Available for freelance work on </em><a href="https://www.upwork.com/freelancers/~0198c4bf74a9c9930f"><em>Upwork</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W-dAnGXCVbQ3qeFro0QvhQ.png" /></figure><p>If you’ve ever worked with biomedical data, you know the gap between “I have this ECG/DICOM/echo dataset” and “I have a working, reproducible analysis pipeline” is enormous — and almost nobody talks about what actually goes wrong in between.</p><p>This article walks through the exact workflow I use across all my projects: biosignal processing, medical image analysis, and deep learning for clinical data. Whether you’re a researcher with ECG data you can’t figure out how to preprocess, or a clinician sitting on a DICOM archive with no idea where to start — this is for you.</p><h3>Step 1: Loading and Parsing the Data</h3><p>The first mistake most people make is treating biomedical data like a CSV. It isn’t.</p><p><strong>For ECG/EEG/PPG/GSR signals</strong>, I use Python’s wfdb (for PhysioNet datasets), scipy.io for MATLAB .mat files, or neurokit2 for general biosignal loading. The first thing I always check:</p><pre>import wfdb<br>import numpy as np</pre><pre>record = wfdb.rdrecord(&#39;mitdb/100&#39;)<br>signal = record.p_signal[:, 0]  # Lead I<br>fs = record.fs                   # sampling frequency — critical<br>print(f&quot;Sampling rate: {fs} Hz | Duration: {len(signal)/fs:.1f}s&quot;)</pre><p>Sampling rate matters more than anything else. If you don’t know your fs, your entire feature extraction will be wrong.</p><p><strong>For DICOM / echocardiography</strong>, I use pydicom:</p><pre>import pydicom<br>import numpy as np</pre><pre>ds = pydicom.dcmread(&#39;echo_file.dcm&#39;)<br>pixel_array = ds.pixel_array  # shape: (frames, height, width) for cine echo<br>print(f&quot;Frames: {pixel_array.shape[0]} | Size: {pixel_array.shape[1:]}&quot;)</pre><p>Echocardiography DICOMs are typically multi-frame (cine loops). Don’t treat them like static images.</p><h3>Step 2: Preprocessing — This is Where Most Projects Break</h3><p><strong>For ECG:</strong></p><pre>import neurokit2 as nk</pre><pre># Bandpass filter (0.5–40 Hz is standard for ECG)<br>ecg_filtered = nk.ecg_clean(signal, sampling_rate=fs, method=&#39;biosppy&#39;)</pre><pre># R-peak detection<br>_, rpeaks = nk.ecg_peaks(ecg_filtered, sampling_rate=fs)<br>r_peak_indices = rpeaks[&#39;ECG_R_Peaks&#39;]</pre><p>The two biggest artifacts I see: <strong>baseline wander</strong> (fix with a high-pass filter at 0.5 Hz) and <strong>powerline interference</strong> (notch filter at 50 or 60 Hz depending on your country).</p><p><strong>For DICOM echocardiography:</strong></p><pre>import cv2</pre><pre>frames = []<br>for i in range(pixel_array.shape[0]):<br>    frame = pixel_array[i]<br>    # Normalize to 0–255<br>    frame_norm = cv2.normalize(frame, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)<br>    # CLAHE for contrast enhancement<br>    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))<br>    frame_enhanced = clahe.apply(frame_norm)<br>    frames.append(frame_enhanced)</pre><h3>Step 3: Feature Extraction — Hand-Crafted First, Then Deep Learning</h3><p>My approach is always <strong>hybrid</strong>: extract meaningful clinical features by hand first, then let a CNN extract global patterns, then fuse both. This is the architecture I used in my current PeerJ submission for MI classification from echocardiography.</p><p><strong>Hand-crafted features (ECG example):</strong></p><pre># HRV features from R-peaks<br>rr_intervals = np.diff(r_peak_indices) / fs * 1000  # in milliseconds</pre><pre>features = {<br>    &#39;mean_rr&#39;:    np.mean(rr_intervals),<br>    &#39;sdnn&#39;:       np.std(rr_intervals),<br>    &#39;rmssd&#39;:      np.sqrt(np.mean(np.diff(rr_intervals)**2)),<br>    &#39;heart_rate&#39;: 60000 / np.mean(rr_intervals)<br>}</pre><p><strong>Deep learning global features (PyTorch):</strong></p><pre>import torch<br>import torchvision.models as models</pre><pre># Load pretrained ResNet, remove final classification layer<br>backbone = models.resnet50(pretrained=True)<br>backbone = torch.nn.Sequential(*list(backbone.children())[:-1])<br>backbone.eval()</pre><pre># Extract global feature vector from echo frame<br>with torch.no_grad():<br>    frame_tensor = preprocess(frame).unsqueeze(0)<br>    global_features = backbone(frame_tensor).squeeze()  # 2048-dim vector</pre><p><strong>Fusion:</strong></p><pre># Concatenate hand-crafted + deep features<br>hand_features = torch.tensor(list(features.values()), dtype=torch.float32)<br>fused = torch.cat([hand_features, global_features])</pre><h3>Step 4: Model Training and Evaluation</h3><p>I always use GitHub + Google Colab for reproducibility. Every experiment is version-controlled, and the Colab notebook runs cleanly without any local setup required by the client.</p><pre>from sklearn.model_selection import StratifiedKFold<br>from sklearn.metrics import roc_auc_score</pre><pre>skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)<br>aucs = []</pre><pre>for fold, (train_idx, val_idx) in enumerate(skf.split(X, y)):<br>    # ... train model, evaluate<br>    auc = roc_auc_score(y_val, y_pred_proba)<br>    aucs.append(auc)<br>    print(f&quot;Fold {fold+1} AUC: {auc:.4f}&quot;)</pre><pre>print(f&quot;Mean AUC: {np.mean(aucs):.4f} ± {np.std(aucs):.4f}&quot;)</pre><h3>Step 5: Visualization and Explainability</h3><p>For medical imaging, results mean nothing without interpretability. I always include Grad-CAM visualizations so the clinician can see <em>where</em> the model is looking:</p><pre>from pytorch_grad_cam import GradCAM<br>from pytorch_grad_cam.utils.image import show_cam_on_image</pre><pre>cam = GradCAM(model=model, target_layers=[model.layer4[-1]])<br>grayscale_cam = cam(input_tensor=input_tensor)<br>visualization = show_cam_on_image(rgb_img, grayscale_cam[0])</pre><h3>Step 6: Statistical Analysis and Writeup</h3><p>After modelling, every result needs proper statistical validation — not just accuracy scores. I run confidence intervals, paired t-tests or Wilcoxon signed-rank tests (depending on distribution), and report all metrics (sensitivity, specificity, AUC, F1) per class.</p><p>The writeup — methodology, results, and Draw.io pipeline figures — is the last step. Most researchers underestimate how much time this takes. I’ve found that having a clear block diagram of your pipeline (built in Draw.io) dramatically speeds up the methodology section and gets you through reviewer comments faster.</p><h3>Work With Me</h3><p>If you’re stuck at any stage of this pipeline — or need someone to build the whole thing from scratch — I’m available on <a href="https://www.upwork.com/freelancers/~0198c4bf74a9c9930f">Upwork</a>.</p><p><strong>I work exclusively with biomedical signals and medical images.</strong> ECG, EEG, PPG, GSR, DICOM, echocardiography, MRI. If that’s your data, message me.</p><p><em>Farhat Basir | Biomedical Engineer | </em><a href="https://farhatbasir.github.io/"><em>Portfolio</em></a><em> | </em><a href="https://linkedin.com/in/farhatbasir"><em>LinkedIn</em></a></p><p><strong>Tags:</strong> ECG processing Python · DICOM medical imaging · echocardiography deep learning · biomedical signal processing · medical image segmentation · PyTorch medical imaging · biosignal feature extraction · EEG classification · cardiac imaging AI</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd8b886dbef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>