0% found this document useful (0 votes)
25 views

Atharva Kulkarni Lab 1 3

The document contains 3 MATLAB assignments related to image processing. Assignment 1 involves performing arithmetic and logical operations on images and displaying the results. Assignment 2 divides an input image into parts and applies operations randomly to each part. Assignment 3 involves selecting random points in an image, calculating distances between the points, and repeating the process to select points of the same intensity.

Uploaded by

vedugamer00
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)
25 views

Atharva Kulkarni Lab 1 3

The document contains 3 MATLAB assignments related to image processing. Assignment 1 involves performing arithmetic and logical operations on images and displaying the results. Assignment 2 divides an input image into parts and applies operations randomly to each part. Assignment 3 involves selecting random points in an image, calculating distances between the points, and repeating the process to select points of the same intensity.

Uploaded by

vedugamer00
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/ 7

ASSIGNMENT 1

Q.1 Write a program to perform basic arithme c and logical opera ons on images
x = imread("/MATLAB Drive/naruto.jpeg");
y = imread("/MATLAB Drive/naruto2.jpeg");
image1 = imresize(x, [size(y,1) size(y,2)]);
result_add = image1 + y;
result_subtract = image1 - y;
result_multiply = image1 .* y;
result_divide = image1 ./ y;
result_and = bitand(image1, y);
result_or = bitor(image1, y);
result_not = imcomplement(image1);
figure; subplot(3, 3, 1); imshow(image1);
title('Input Image 1');
subplot(3, 3, 2); imshow(y);
title('Input Image 2');
subplot(3, 3, 3); imshow(result_add);
title('Addition');
subplot(3, 3, 4); imshow(result_subtract);
title('Subtraction');
subplot(3, 3, 5); imshow(result_multiply);
title('Multiplication');
subplot(3, 3, 6); imshow(result_divide);
title('Division');
subplot(3, 3, 7); imshow(result_and);
title('AND');
subplot(3, 3, 8);
imshow(result_or);
title('OR');
subplot(3, 3, 9);
imshow(result_not);
title('NOT on Image 1');

OUTPUT:
Q.2 Divide the image into N equal parts and perform the Above opera on randomly on
each part.
input_image = imread("/MATLAB Drive/minato.jpeg");
[rows, cols, ~] = size(input_image);
N=5
part_rows= floor(rows / N);
part_cols = floor(cols / N);
starting_points = randperm(N^2, N);
figure;
for i = 1:N
row_start = 1 + part_rows * floor((starting_points(i) - 1) / N);
row_end = row_start + part_rows - 1;

col_start = 1 + part_cols * mod((starting_points(i) - 1), N);


col_end = col_start + part_cols - 1;

part = input_image(row_start:row_end, col_start:col_end, :);


result_add = part + randi(100);
result_subtract = part - randi(100);
result_multiply = part .* (randi(100) / 100);
result_divide = part ./ (randi(100) + 1);
result_and = bitand(part, randi(255, size(part), 'uint8'));
result_or = bitor(part, randi(255, size(part), 'uint8'));
result_not = imcomplement(part);

subplot(N, 7, (i - 1) * 7 + 1); imshow(part);


title('Original');
subplot(N, 7, (i - 1) * 7 + 2); imshow(result_add);
title('Add.');
subplot(N, 7, (i - 1) * 7 + 3); imshow(result_subtract);
title('Sub.');
subplot(N, 7, (i - 1) * 7 + 4); imshow(result_multiply);
title('Multi.');
subplot(N, 7, (i - 1) * 7 + 5); imshow(result_divide);
title('Div.');
subplot(N, 7, (i - 1) * 7 + 6); imshow(result_and);
title('AND');
subplot(N, 7, (i - 1) * 7 + 7); imshow(result_or);
title('OR');
end
OUTPUT:
ASSIGNMENT 2
Q.1 Calculate 4 path, m-path, 8-path for given image. Use pixel intensity values and
calculate features in terms of path.
image = imread("/MATLAB Drive/naruto.jpeg");
gray_image = rgb2gray(image);
four_path = [0 1; 1 0; 1 1; -1 1];
m_path = [0 1; 1 1; 2 1; 3 1];
eight_path = [0 1; 1 0; 1 1; -1 1; 0 -1; -1 0; -1 -1; 1 -1];
four_path_features = zeros(size(four_path, 1), 1);
m_path_features = zeros(size(m_path, 1), 1);
eight_path_features = zeros(size(eight_path,1),1);
for i = 1:size(four_path, 1)
four_path_features(i) = sum(sum(imtranslate(gray_image, four_path(i, :))));
end
for i = 1:size(m_path, 1)
m_path_features(i) = sum(sum(imtranslate(gray_image, m_path(i, :))));
end
for i = 1:size(eight_path, 1)
eight_path_features(i) = sum(sum(imtranslate(gray_image, eight_path(i, :))));
end
disp('4-path features:');
disp(four_path_features);
disp('m-path features:');
disp(m_path_features);
disp('8-path features:');
disp(eight_path_features);

OUTPUT:
ASSIGNMENT 3

Q.1 Select P & Q points randomly in an image and calculate the distance
imagePath = "/MATLAB Drive/naruto.jpeg";
image = imread(imagePath);
imshow(image);
title('Image with Two Random Points');
[height, width, ~] = size(image);
randomPoint1 = randi([1, width], 1, 2);
randomPoint2 = randi([1, width], 1, 2);
hold on;
scatter(randomPoint1(1), randomPoint1(2), 50, 'r', 'filled');
scatter(randomPoint2(1), randomPoint2(2), 50, 'g', 'filled');
hold off;
euclideanDist = norm(randomPoint2 - randomPoint1);
manhattanDist = sum(abs(randomPoint2 - randomPoint1));
chebyshevDist = max(abs(randomPoint2 - randomPoint1));
minkowskiDist = norm(randomPoint2 - randomPoint1, 3);
cosineDist = 1 - dot(randomPoint1, randomPoint2) / (norm(randomPoint1) *
norm(randomPoint2));
correlationDist = 1 - corr2(randomPoint1, randomPoint2);
hammingDist = sum(randomPoint1 ~= randomPoint2) / numel(randomPoint1);
fprintf('Random Point 1: (%d, %d)\n', randomPoint1(1), randomPoint1(2));
fprintf('Random Point 2: (%d, %d)\n', randomPoint2(1), randomPoint2(2));
fprintf('Euclidean Distance: %.2f\n', euclideanDist);
fprintf('Manhattan Distance: %.2f\n', manhattanDist);
fprintf('Chebyshev Distance: %.2f\n', chebyshevDist);
fprintf('Minkowski Distance: %.2f\n', minkowskiDist);
fprintf('Cosine Distance: %.2f\n', cosineDist);
fprintf('Correlation Distance: %.2f\n', correlationDist);
fprintf('Hamming Distance: %.2f\n', hammingDist);
OUTPUT:
Q.2 Select P & Q in an Image where pixel intensities are same and calculate the distance
imagePath = '/MATLAB Drive/gojo.jpeg';
image = imread(imagePath);
imshow(image);
title('Image with two random points of same intensity');
% Get image dimensions
[height, width, ~] = size(image);
% Step 2: Find two random points with the same intensity
intensity = randi([0, 255]); % Random intensity value between 0 and 255
matchingPoints = find(image == intensity); % Find all points with the same intensity
numMatchingPoints = numel(matchingPoints);
% Check if there are enough matching points
if numMatchingPoints < 2
error('Not enough points with the same intensity.');
end
% Randomly select two points from the matching points
randIndices = randperm(numMatchingPoints, 2);
point1Index = matchingPoints(randIndices(1));
point2Index = matchingPoints(randIndices(2));
% Convert linear index to (y, x) coordinates
[point1Y, point1X] = ind2sub([height, width], point1Index);
[point2Y, point2X] = ind2sub([height, width], point2Index);
% Display the random points with the same intensity on the image
hold on;
scatter(point1X, point1Y, 50, 'r', 'filled');
scatter(point2X, point2Y, 50, 'g', 'filled');
hold off;
% Step 3: Calculate distances
euclideanDistance = norm([point2X, point2Y] - [point1X, point1Y]);
manhattanDistance = abs(point2X - point1X) + abs(point2Y - point1Y);
chebyshevDistance = max(abs(point2X - point1X), abs(point2Y - point1Y));
minkowskiDistance = norm([point2X, point2Y] - [point1X, point1Y], 3);
cosineDistance = 1 - dot([point1X, point1Y], [point2X, point2Y]) / ...
(norm([point1X, point1Y]) * norm([point2X, point2Y]));
correlationDistance = 1 - corr2([point1X, point1Y], [point2X, point2Y]);
hammingDistance = sum([point1X, point1Y] ~= [point2X, point2Y]) / 2;
fprintf('Point 1: (%d, %d), Intensity: %d\n', point1X, point1Y, intensity);
fprintf('Point 2: (%d, %d), Intensity: %d\n', point2X, point2Y, intensity);
fprintf('Euclidean Distance: %.2f\n', euclideanDistance);
fprintf('Manhattan Distance: %.2f\n', manhattanDistance);
fprintf('Chebyshev Distance: %.2f\n', chebyshevDistance);
fprintf('Minkowski Distance: %.2f\n', minkowskiDistance);
fprintf('Cosine Distance: %.2f\n', cosineDistance);
fprintf('Correlation Distance: %.2f\n', correlationDistance);
fprintf('Hamming Distance: %.2f\n', hammingDistance);
OUTPUT:

You might also like