Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.5 kB
3
Indexable
Never
img = imread('image.jpg');

gray_img = rgb2gray(img);

% Downsample the image
downsampled_img = gray_img(1:4:end, 1:4:end);
% Quantize the image to 8 levels
quantized_img = uint8(8 * floor(double(downsampled_img) / 32));
% Display the images
figure;
subplot(1,3,1); imshow(gray_img); title('Original Image');
subplot(1,3,2); imshow(downsampled_img); title('Downsampled Image');
subplot(1,3,3); imshow(quantized_img); title('Quantized Image');





function [euclidean_dist, manhattan_dist, chessboard_dist] = 

distance_measures(p1, p2)

 euclidean_dist = sqrt(sum((p1 - p2).^2));
 manhattan_dist = sum(abs(p1 - p2));
 chessboard_dist = max(abs(p1 - p2));
end
% Example usage
p1 = [10, 20];
p2 = [30, 40];
[euclidean_dist, manhattan_dist, chessboard_dist] = distance_measures(p1, p2);




img = imread('binary_image.jpg');

pixel = [50, 50]; % Example pixel coordinates

% Define neighbor offsets for 4-connected and 8-connected neighbors
offsets_4 = [-1 0; 1 0; 0 -1; 0 1];
offsets_8 = [-1 -1; -1 0; -1 1; 0 -1; 0 1; 1 -1; 1 0; 1 1];
% Find neighbors
neighbors_4 = bsxfun(@plus, pixel, offsets_4);
neighbors_8 = bsxfun(@plus, pixel, offsets_8);
% Display the image with neighbors highlighted
figure; imshow(img); hold on;
plot(pixel(2), pixel(1), 'ro'); % Central pixel
plot(neighbors_4(:,2), neighbors_4(:,1), 'bs'); % 4-connected neighbors
plot(neighbors_8(:,2), neighbors_8(:,1), 'g*'); % 8-connected neighbors
title('Neighbors');
Leave a Comment