Skip to main content

Chest X-ray Generation using GANs

 

Imagine doctors need chest X-rays to detect diseases like pneumonia. But collecting a huge number of X-rays is hard — sometimes there aren’t enough, or sharing them is restricted because of privacy rules.

This is where Artificial Intelligence (AI) comes in. With the right techniques, we can teach a computer to generate new chest X-rays that look real. These synthetic images can then be used to train other AI systems and support doctors without needing endless real scans.

We use something called a GAN (Generative Adversarial Network). You can think of it as a competition between two players:

  • The Generator (the artist): tries to create fake X-rays.

  • The Discriminator (the critic): tries to tell if an image is real or fake.

The two AIs play a game:

  1. Start with random noise (like static on a TV).

  2. The generator turns it into an image.

  3. The discriminator checks: real or fake?

  4. Both improve, step by step, through thousands of rounds.

The generator improves until it fools the discriminator. Over time, the fake X-rays start to look real.

  • Input (latent vector z): Random numbers, usually sampled from a normal distribution.

  • Generator (Decoder): Takes z and “decodes” it into a 256×256 grayscale image using layers of transposed convolutions.

  • Discriminator (Encoder): Acts like a feature extractor, scanning the image with convolutional filters and predicting a probability: real vs. fake.

The hardest part is finding the right balance between the two:

  • If the discriminator is too strong, it easily spots fakes and the generator never learns.

  • If the generator is too strong, it might fool the discriminator with unrealistic patterns (mode collapse: generating the same “fake” image every time).

To keep training stable, we use tricks like:

  • Label smoothing: instead of saying “this is 100% real,” we label real images as 0.9 instead of 1.0.

  • Label flipping: occasionally marking a fake as real to confuse the discriminator.

  • Noise injection: adding randomness to the inputs so the model doesn’t overfit.

  • Balanced training steps: sometimes updating the generator multiple times per discriminator step

Early stage (Epoch ~500): blurry, noisy, clearly fake.

Middle stage (Epoch ~2000): structures of lungs and chest become visible.

Late stage (Epoch ~3000+): images are so realistic that even experts may struggle to tell them apart from real X-rays.

At the beginning (500 epochs), images look blurry and messy.
Later (3000 epochs), you can clearly see lungs and chest structures. 

  • Helps create more data for AI models.

  • Can be used to simulate rare diseases.

  • Saves time and cost compared to collecting new real scans.

In the future, this method could even generate high-resolution (512×512) scans or condition images on specific diseases.


In short: We trained a computer to imagine new chest X-rays by playing a game between two AIs. And the results can actually help real doctors and researchers! 

Github 

DataBase[Xray images]

bozokidagomir@gmail.com 

Comments

Popular posts from this blog

How I Built a Bilingual Voice Assistant with Two Brains (and What I Learned Along the Way)

   Introduction This project is the practical part of my Master’s thesis , developed during my Erasmus+ exchange at the University of Patras , within the ESDA Lab (Embedded Systems and Digital Applications) . What started as a standard “upgrade the assistant” task turned into a full-on multilingual, multi-component NLP system. The goal was to make a voice assistant smarter — not just technically smarter, but able to handle real, everyday language, in both English and Greek . I took Kalliope , an open-source modular voice assistant, and upgraded it with two powerful LLMs : One to recognize what the user wants ( intent classification ) One to generate a helpful response if the first one gets confused ( generative fallback ) On top of that, I added typo correction, semantic search, and multilingual support. I learned a ton — from dealing with transformer models and vector search, to debugging legacy Python dependencies at midnight on a university server.   Why Ka...

Deep Learning Algorithm for Lip Reading without audio - Just based on Lip movement!

Author: Dragomir Božoki     1. Introduction      During the final year of my Bachelor's studies, once I realized I would pass all my exams on time, I knew it was time to choose a topic for my thesis. Throughout my studies, I gradually became interested in signal processing – a field where you can work with various types of signals to generate new images, analyze text, interpret brain activity, and more.      This interest grew even stronger when AI started booming in late 2022. Topics related to machine learning and data analysis suddenly became the center of attention across the tech industry. That was the moment I knew – this is the field I want to specialize in.      When I spoke with my professors about potential thesis topics, they proposed an idea that instantly caught my attention: teaching a machine to understand language purely through visual input—without any audio—by analyzing only lip movements. The concept sounded abso...

Analyzing 34 GB of Wikipedia Text Using Information Theory and Machine Learning

Author: Dragomir Božoki GitHub: https://github.com/DragomirBozoki/wiki-feature-selection-pysp Introduction Wikipedia contains millions of English-language articles on a wide range of topics. If we wanted to understand how language works — such as which words tend to appear together or which words are most relevant to a topic — we would need to analyze a huge amount of text. This project aimed to do exactly that, but automatically, using tools from Big Data processing , information theory , and machine learning . Step 1: Data Preparation Wikipedia dumps come in raw XML format, which includes not only article content but also technical details, formatting tags, and metadata that are not useful for language analysis. The first step was to clean the text , which involved: Removing all HTML, XML, and Wiki-specific tags Converting all text to lowercase Removing punctuation Splitting text into single words (unigrams) and consecutive word pairs (bigrams) I used WikiExtractor ...