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

Digital Image and Video Processing - Assignment1

Uploaded by

hopeless2693
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 views5 pages

Digital Image and Video Processing - Assignment1

Uploaded by

hopeless2693
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
You are on page 1/ 5

Digital Image and Video Processing - Assignment 1

2. Convert an RGB image HSV and display the individual H, S, and V


channels

[filename, pathname] = uigetfile({'*.jpg;*.png;*.bmp'}, 'Select an Image');

if filename ~= 0
image = imread(fullfile(pathname, filename));

hsv_image = rgb2hsv(image);

H = hsv_image(:,:,1);
S = hsv_image(:,:,2);
V = hsv_image(:,:,3);

figure;

subplot(1,4,1);
imshow(image);
title('Original RGB Image');

subplot(1,4,2);
imshow(H);
title('Hue Channel');

subplot(1,4,3);
imshow(S);
title('Saturation Channel');

subplot(1,4,4);
imshow(V);
title('Value Channel');
else
error('No file selected.');
end
4. Apply a contrast stretching transformation to a gray scale image
[filename, pathname] = uigetfile({'*.jpg;*.png;*.bmp'}, 'Select an Image');
if filename ~= 0
image = imread(fullfile(pathname, filename));
else
error('No file selected.');
end

if size(image, 3) == 3
image = rgb2gray(image);
end

I_min = double(min(image(:)));
I_max = double(max(image(:)));

stretched_image = uint8(255 * (double(image) - I_min) / (I_max - I_min));

figure;

subplot(1,2,1);
imshow(image);
title('Original Grayscale Image');

subplot(1,2,2);
imshow(stretched_image);
title('Contrast Stretched Image');
6. Implement a median filter on an RGB image to remove noise.
[filename, pathname] = uigetfile({'*.jpg;*.png;*.bmp'}, 'Select an Image');
if filename ~= 0
image = imread(fullfile(pathname, filename));
else
error('No file selected.');
end

image = im2double(image);

R = medfilt2(image(:,:,1), [3 3]);
G = medfilt2(image(:,:,2), [3 3]);
B = medfilt2(image(:,:,3), [3 3]);

filtered_image = cat(3, R, G, B);

figure;

subplot(1,2,1);
imshow(image);
title('Original Noisy Image');

subplot(1,2,2);
imshow(filtered_image);
title('Median Filtered Image');

8. Implement discrete cosine transform(DCT) on a 8x8 block of an image


and reconstruct it.
[filename, pathname] = uigetfile({'*.jpg;*.png;*.bmp'}, 'Select an Image');
if filename ~= 0
image = imread(fullfile(pathname, filename));
else
error('No file selected.');
end

if size(image, 3) == 3
image = rgb2gray(image);
end

image = double(image);

block = image(1:8, 1:8);

dct_block = dct2(block);

reconstructed_block = idct2(dct_block);

figure;

subplot(1,3,1);
imshow(uint8(block));
title('Original 8x8 Block');

subplot(1,3,2);
imshow(log(abs(dct_block) + 1), []);
title('DCT Coefficients');

subplot(1,3,3);
imshow(uint8(reconstructed_block));
title('Reconstructed Block (IDCT)');

10. Obtain histogram of a grayscale image


[filename, pathname] = uigetfile({'*.jpg;*.png;*.bmp'}, 'Select an Image');
if filename ~= 0
image = imread(fullfile(pathname, filename));
else
error('No file selected.');
end
figure;
subplot(1,2,1);
imshow(image);
title('Grayscale Image');

subplot(1,2,2);
imhist(image);
title('Histogram of the Image');
xlabel('Pixel Intensity (0-255)');
ylabel('Frequency');

You might also like