Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
2.3 kB
3
Indexable
Never
img = imread('noisy_image.jpg');

gray_img = rgb2gray(img);

% Apply linear filter (averaging)
h = fspecial('average', [5 5]);
linear_filtered_img = imfilter(gray_img, h);
% Apply non-linear filter (median)
nonlinear_filtered_img = medfilt2(gray_img, [5 5]);
% Display the results
figure;
subplot(1,3,1); imshow(gray_img); title('Original Image');
subplot(1,3,2); imshow(linear_filtered_img); title('Linear Filtered Image');
subplot(1,3,3); imshow(nonlinear_filtered_img); title('Non-linear Filtered 
Image');





img = imread('image.jpg');

% Simulate processing: Apply Gaussian blur

h = fspecial('gaussian', [5 5], 2);
processed_img = imfilter(img, h);
% Display the blurred image
imshow(processed_img);
title('Blurred Image');




img = imread('binary_image.jpg');

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

% Calculate neighbors (4-connectivity)
offsets_4 = [-1 0; 1 0; 0 -1; 0 1];
neighbors_4 = bsxfun(@plus, pixel, offsets_4);
% Calculate neighbors (8-connectivity)
offsets_8 = [-1 -1; -1 0; -1 1; 0 -1; 0 1; 1 -1; 1 0; 1 1];
neighbors_8 = bsxfun(@plus, pixel, offsets_8);
% Display the original image with neighbors highlighted
figure; imshow(img); hold on;
plot(pixel(2), pixel(1), 'ro'); % Original 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 and Connectivity');
% Calculate the number of connected components
[~, num_components] = bwlabel(img, 8);
disp(['Number of connected components: ', num2str(num_components)]);




img = imread('image.jpg');

gray_img = rgb2gray(img);

gamma_value = 2.0; % Example gamma value
gamma_corrected_img = imadjust(gray_img, [], [], gamma_value);
imshowpair(gray_img, gamma_corrected_img, 'montage');




img = imread('image.jpg');

gray_img = rgb2gray(img);

equalized_img = histeq(gray_img);
imshowpair(gray_img, equalized_img, 'montage');




img = imread('image.jpg');

gray_img = rgb2gray(img);

% Smoothing filter
average_filter = fspecial('average', [3 3]);
smoothed_img = imfilter(gray_img, average_filter);
% Sharpening filter
laplacian_filter = fspecial('laplacian');
sharpened_img = imfilter(gray_img, laplacian_filter);
imshowpair(smoothed_img, sharpened_img, 'montage');

Leave a Comment