You are on page 1of 11

EXPERIMENT-06

1. Read an RGB image and extract each color component and display

it.

rgbImage = imread('flamingos.jpg');

redComponent = rgbImage(:, :, 1);


greenComponent = rgbImage(:, :, 2);
blueComponent = rgbImage(:, :, 3);

subplot(1, 3, 1);
imshow(redComponent);
title('Red Component');

subplot(1, 3, 2);
imshow(greenComponent);
title('Green Component');

subplot(1, 3, 3);
imshow(blueComponent);
title('Blue Component');

sgtitle('RGB Color Components');

OUTPUT:
2. Repeat Q1 using SIMULINK.
3. Read an RGB image. Convert it into YIQ format. [Use rgb2ntsc()].

Apply histogram equalization on Y component only. Convert it to

RGB and display the result.

originalImage = imread('flamingos.jpg');

yiqImage = rgb2ntsc(originalImage);
yComponent = yiqImage(:,:,1);
yComponentEqualized = histeq(yComponent);

yiqImageEqualized = yiqImage;
yiqImageEqualized(:,:,1) = yComponentEqualized;

rgbImageEqualized = ntsc2rgb(yiqImageEqualized);

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

subplot(1, 2, 2);
imshow(rgbImageEqualized);
title('Equalized Image');

imwrite(rgbImageEqualized, 'equalized_image.jpg');

OUTPUT:
4. Repeat Q3 using SIMULINK.

OUTPUT:

5. Read a color image. Corrupt the image by salt and pepper noise.

Display the corrupted image. Apply median filter on each plane of

the corrupted image and display the result. [Use medfilt2()]


originalImage = imread('forest.tif');

corruptedImage = imnoise(originalImage, 'salt & pepper', 0.05);

figure;
subplot(1, 2, 1);
imshow(originalImage);
title('Original Image');

subplot(1, 2, 2);
imshow(corruptedImage);
title('Corrupted Image');

filteredImage = corruptedImage;

for channel = 1:3


filteredImage(:, :, channel) = medfilt2(corruptedImage(:, :, channel), [3, 3]);
end

figure;
subplot(1, 2, 1);
imshow(corruptedImage);
title('Corrupted Image');

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

OUTPUT:
6. Repeat Q5 using Simulink.

7. Read an RGB image. Convert it into YIQ format. Apply high pass-
Filtering on Y component only. Convert it to RGB and display the

result. (Apply filter h= [-1 -1 -1; -1 8 -1; -1 -1 -1])

originalImage = imread('flamingos.jpg');

yiqImage = rgb2ntsc(originalImage);

highPassFilter = [-1 -1 -1; -1 8 -1; -1 -1 -1];


yComponent = yiqImage(:,:,1);
filteredYComponent = imfilter(yComponent, highPassFilter, 'replicate');

filteredYIQImage = yiqImage;
filteredYIQImage(:,:,1) = filteredYComponent;

filteredRGBImage = ntsc2rgb(filteredYIQImage);

figure;
subplot(1, 2, 1);
imshow(originalImage);
title('Original Image');

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

OUTPUT:

You might also like