0% found this document useful (0 votes)
18 views2 pages

Matlab Code

The document contains two versions of MATLAB code for image preprocessing, including resizing, converting to grayscale, sharpening, and applying CLAHE. It also features binary thresholding, mathematical morphology operations like skeletonization, erosion, and dilation, followed by contour detection to highlight veins in the image. The final output displays the original image alongside the detected contours.

Uploaded by

Naveen Mugesh H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Matlab Code

The document contains two versions of MATLAB code for image preprocessing, including resizing, converting to grayscale, sharpening, and applying CLAHE. It also features binary thresholding, mathematical morphology operations like skeletonization, erosion, and dilation, followed by contour detection to highlight veins in the image. The final output displays the original image alongside the detected contours.

Uploaded by

Naveen Mugesh H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Matlab Code (Preprocessing Given by sir)

image = imread('image2.jpg');
M = 256;
k = 20;
resized_image = imresize(image, [M M]);
gray_image = rgb2gray(resized_image);
sharpened_image = imsharpen(gray_image);
median_filtered_image = medfilt2(sharpened_image);
clahe_image = adapthisteq(median_filtered_image);
binary_image = zeros(size(clahe_image));
for i = 1:size(clahe_image, 1)
for j = 1:size(clahe_image, 2)
if clahe_image(i,j) > 225 - k
binary_image(i,j) = 255;
else
binary_image(i,j) = 0;
end
end
end
skeletonized_image = bwmorph(binary_image, 'skel', Inf);
eroded_image = imerode(skeletonized_image, strel('square', 3));
dilated_image = imdilate(eroded_image, strel('square', 5));
contours = bwboundaries(dilated_image);
imshow(image);
hold on;
for k = 1:length(contours)
boundary = contours{k};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2);
end
hold off;

Matlab Code (Preprocessing)

% Load Image
image = imread('image.jpg');

% Parameters
M = 256;
k = 20;
Threshold = 225;

% Preprocessing
resized_image = imresize(image, [M M]);
gray_image = rgb2gray(resized_image);
sharpened_image = imsharpen(gray_image);
smoothed_image = medfilt2(sharpened_image);
clahe_image = adapthisteq(smoothed_image);

% Thresholding
binary_image = zeros(size(clahe_image));
for row = 1:size(clahe_image, 1)
for col = 1:size(clahe_image, 2)
if clahe_image(row, col) > (Threshold - k)
binary_image(row, col) = 255;
else
binary_image(row, col) = 0;
end
end
end

% Mathematical Morphology
skeletonized_image = bwmorph(binary_image, 'skel', Inf);
eroded_image = imerode(skeletonized_image, strel('square', 3));
dilated_image = imdilate(eroded_image, strel('square', 5));

% Contour Detection
contours = bwboundaries(dilated_image);

% Display Results
figure;
subplot(1, 2, 1);
imshow(image);
title('Original Image');

subplot(1, 2, 2);
imshow(image);
hold on;
for k = 1:length(contours)
boundary = contours{k};
plot(boundary(:, 2), boundary(:, 1), 'g', 'LineWidth', 2);
end
hold off;
title('Detected Veins');

Matlab code

You might also like