0% found this document useful (0 votes)
9 views6 pages

Lab08

The document outlines a lab assignment for the Digital Image Processing course, focusing on tumor detection using various segmentation techniques. It includes methods such as local, global, variable, and adaptive thresholding, as well as edge detection approaches like Sobel and Canny. Additionally, it covers region growing and region splitting and merging techniques for tumor segmentation, providing MATLAB code for implementation.

Uploaded by

tridib.thk.bd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Lab08

The document outlines a lab assignment for the Digital Image Processing course, focusing on tumor detection using various segmentation techniques. It includes methods such as local, global, variable, and adaptive thresholding, as well as edge detection approaches like Sobel and Canny. Additionally, it covers region growing and region splitting and merging techniques for tumor segmentation, providing MATLAB code for implementation.

Uploaded by

tridib.thk.bd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Semester: Fall 2024

Course Title: Digital Image Processing


Course Code: CSE438
Section: 01

Lab 08

Submitted To:
Professor Dr. Ahmed Wasif Reza
Department of Computer Science and Engineering
East West University

Submitted By:
Korobi Sarker
ID: 2020-1-60-161

Submission Date: 16/01/2025


1. Detect the tumor from the image (Figure 1) using the segmentation approaches listed
below: (Outline the segmented object to highlight the tumor. You can crop the image for
accurate segmentation.)
i) Similarity approaches:
a) Local/Regional Thresholding
b) Global Thresholding
c) Variable Thresholding
d) Dynamic/Adaptive Thresholding
ii) Discontinuity approaches: Edge Detection (Sobel, Canny, Prewitt)

Solution:
image = imread('Picture1.png'); % Replace with your image file
figure;
subplot(2,4,1);
imshow(image);
title('Original Image');
grayImage = rgb2gray(image);

roi = grayImage(100:250, 100:250);


localThresh = graythresh(roi);
localBinaryImage = imbinarize(roi, localThresh);
subplot(2,4,2);
imshow(localBinaryImage);
title('Local Thresholding');

globalThresh = graythresh(grayImage);
globalBinaryImage = imbinarize(grayImage, globalThresh);
subplot(2,4,3);
imshow(globalBinaryImage);
title('Global Thresholding');

blockSize = 50;
variableBinaryImage = adaptiveThresholding(grayImage, blockSize);
subplot(2,4,4);
imshow(variableBinaryImage);
title('Variable Thresholding');

adaptiveBinaryImage = imbinarize(grayImage, 'adaptive', 'ForegroundPolarity', 'bright', 'Sensitivity', 0.4);


subplot(2,4,5);
imshow(adaptiveBinaryImage);
title('Adaptive Thresholding');

sobelEdges = edge(grayImage, 'Sobel');


subplot(2,4,6);
imshow(sobelEdges);
title('Sobel Edge Detection');
cannyEdges = edge(grayImage, 'Canny');
subplot(2,4,7);
imshow(cannyEdges);
title('Canny Edge Detection');

prewittEdges = edge(grayImage, 'Prewitt');


subplot(2,4,8);
imshow(prewittEdges);
title('Prewitt Edge Detection');

function binaryImage = adaptiveThresholding(grayImage, blockSize)


[rows, cols] = size(grayImage);
binaryImage = false(rows, cols);
for i = 1:blockSize:rows
for j = 1:blockSize:cols
rowEnd = min(i+blockSize-1, rows);
colEnd = min(j+blockSize-1, cols);
block = grayImage(i:rowEnd, j:colEnd);
thresh = graythresh(block);
binaryImage(i:rowEnd, j:colEnd) = imbinarize(block, thresh);
end
end
end
2. Segment the tumor from Figure 1 by using:
i. Region growing approach
ii. Region Splitting and Merging approach

Solution:
image = imread('Picture1.png');
subplot(1,3,1);
imshow(image);
title('Original Image');

grayImage = rgb2gray(image);

seedPoint = [150, 150];


threshold = 0.2;
regionGrowingMask = regionGrowing(grayImage, seedPoint, threshold);
subplot(1,3,2);
imshow(regionGrowingMask);
title('Region Growing Segmentation');

threshold = 15; % Intensity difference threshold for splitting (adjust as needed)


regionSplitMergeMask = regionSplitAndMerge(grayImage, threshold);
subplot(1,3,3);
imshow(regionSplitMergeMask, []);
title('Region Splitting and Merging Segmentation');

function outputMask = regionGrowing(inputImage, seedPoint, threshold)

inputImage = double(inputImage) / 255;


[rows, cols] = size(inputImage);

outputMask = false(rows, cols);


outputMask(seedPoint(1), seedPoint(2)) = true;

seedValue = inputImage(seedPoint(1), seedPoint(2));

pixelStack = [seedPoint];

neighbors = [-1, 0; 1, 0; 0, -1; 0, 1; -1, -1; -1, 1; 1, -1; 1, 1];

while ~isempty(pixelStack)
currentPixel = pixelStack(end, :);
pixelStack(end, :) = [];
for i = 1:size(neighbors, 1)
neighborRow = currentPixel(1) + neighbors(i, 1);
neighborCol = currentPixel(2) + neighbors(i, 2);
if neighborRow > 0 && neighborRow <= rows && neighborCol > 0 && neighborCol <= cols
if ~outputMask(neighborRow, neighborCol) % If not already segmented
intensityDiff = abs(inputImage(neighborRow, neighborCol) - seedValue);
if intensityDiff <= threshold
outputMask(neighborRow, neighborCol) = true;
pixelStack = [pixelStack; neighborRow, neighborCol];
end
end
end
end
end
end
function outputMask = regionSplitAndMerge(inputImage, threshold)

inputImage = double(inputImage);
[rows, cols] = size(inputImage);
outputMask = zeros(rows, cols); % Initialize mask
regions = splitRegion(inputImage, 1, rows, 1, cols, threshold);
outputMask = mergeRegions(regions, inputImage, threshold);
end
function regions = splitRegion(inputImage, rStart, rEnd, cStart, cEnd, threshold)
subImage = inputImage(rStart:rEnd, cStart:cEnd);
intensityRange = range(subImage(:));
if intensityRange > threshold && (rEnd - rStart > 1) && (cEnd - cStart > 1)
midRow = floor((rStart + rEnd) / 2);
midCol = floor((cStart + cEnd) / 2);
regions1 = splitRegion(inputImage, rStart, midRow, cStart, midCol, threshold);
regions2 = splitRegion(inputImage, rStart, midRow, midCol+1, cEnd, threshold);
regions3 = splitRegion(inputImage, midRow+1, rEnd, cStart, midCol, threshold);
regions4 = splitRegion(inputImage, midRow+1, rEnd, midCol+1, cEnd, threshold);
regions = [regions1; regions2; regions3; regions4];
else
regions = [rStart, rEnd, cStart, cEnd];
end
end
function outputMask = mergeRegions(regions, inputImage, threshold)
[rows, cols] = size(inputImage);
outputMask = zeros(rows, cols);
for i = 1:size(regions, 1)
rStart = regions(i, 1);
rEnd = regions(i, 2);
cStart = regions(i, 3);
cEnd = regions(i, 4);
subImage = inputImage(rStart:rEnd, cStart:cEnd);
meanIntensity = mean(subImage(:));
if meanIntensity > threshold
outputMask(rStart:rEnd, cStart:cEnd) = 1;
end
end
end

You might also like