Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Brain Tumor Segmentation with U-Net #2: MRI Preprocessing & Image + Mask Augmentation Simultaneously”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
This is the final result, one brain MRI image is rotated, zoomed, shifted, and flipped randomly, and the yellow line tumor boundary moves precisely with the image. This is the correct augmentation for segmentation. Let's start. Hello, welcome to episode two of the brain tumor segmentation series with metaheuristic optimized units. Our data is ready to be loaded. Now we are preparing it for training. MRI intensity normalization, and data augmentation. There is one important rule in segmentation. Every geometric transformation applied to the image must be applied exactly the same to the mask.
Create a dataset file underscore brain dot py. First, the augmentation function. With a 50% chance, the image and mask are flipped horizontally together. Then we create one affine transformation matrix with random rotation plus or minus 15 degrees, scale 90-110%, and small shift. The same matrix is used for the image and mask. The image uses linear interpolation, while the mask uses nearest to avoid fractional values at the tumor edges. Finally, the image brightness is slightly changed, only the image, because brightness does not change the tumor location.
Next, normalization. MRI intensity does not have a standard scale, it varies between machines and patients. Therefore, we use z-score per image, subtract the mean and divide by the standard deviation. The brain data class returns a 3-channel image tensor and a 1-channel mask, with augmentation only for the training data. The loader function creates a data loader for the training, validation, or test part. The portion parameter allows us to use part of the training data, which will be useful during metaheuristic optimization. Now create the preprocessing file underscore brain dot pye to see the results.
We select the slice with the widest tumor. Before normalization, pixel values range from 0 to 188. We then normalize to mean 0 and standard deviation 1.
Next, we display the original image and 4 augmented results. Notice the bottom line, the yellow line tumor boundary always sticks precisely to the tumor area, even if the image is rotated, zoomed, shifted, or flipped. If the image and mask are augmented separately with different random numbers, the label becomes incorrect and the model learns the wrong things.
Finally, we take one batch from the training loader. Its shape is 32 images, 3 channels, 96x96, and mask 1 channel. In this batch, tumor pixels are only about 1%. The number of augmentations is 2,680 for training, 575 for validation, and 674 for testing.
Done. We have created Z-score normalization, identical geometric augmentation for both images and masks, as well as PyTorch datasets and data loaders. In the next episode, we will build the UNET architecture from scratch, encoder, decoder, and skip connections. Currently working on a thesis, dissertation, or AI research in the field of medical image segmentation? Cerdas Inovasi Digital helps with deep learning implementation, from UNET segmentation, PSO and Grey Wolf metaheuristic optimization, up to DAIS, IOU evaluation, and result writing, as well as opening deep learning courses with PyTorch. Want to master the entire series? From MRI brain datasets to optimized UNET with metaheuristics? All 6 episodes, complete with PDF step-by-step guides and source code, are available for premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or one-time payment of Rp999.000 for lifetime access. Want a single class only? Buy single classes with lifetime access. Subscribe now on the premium page cerdasinovasidigital.com Contact our WhatsApp, or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →