0% found this document useful (0 votes)
6 views9 pages

Experimet 7

Digital Image processing experiment in matlab 4

Uploaded by

Yash Verma
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)
6 views9 pages

Experimet 7

Digital Image processing experiment in matlab 4

Uploaded by

Yash Verma
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/ 9

EXPERIMET 7

Code 1

clc;clear all;close all;


RGB=imread('C:\Users\dsplab\Downloads\sim.jpg');
R=RGB;
G=RGB;
B=RGB;
R1=RGB(:,:,1);
figure,imshow(R1)
R(:,:,2)=0;
%figure,imshow(R)
R(:,:,3)=0;
% figure,imshow(R)
G(:,:,1)=0;
G(:,:,3)=0;
B(:,:,1)=0;
B(:,:,2)=0;
figure
subplot(2,2,1),imshow(RGB),title('original image')
subplot(2,2,2),imshow(R),title('Red Component')
subplot(2,2,3),imshow(G),title('Green Component')
subplot(2,2,4),imshow(B),title('Blue Component')
a1=RGB;
b1=RGB;
c1=RGB;
a1(:,:,1)=0;
b1(:,:,2)=0;
c1(:,:,3)=0;
figure,
subplot(2,2,1),imshow(RGB),title('original image')
subplot(2,2,2),imshow(a1),title('Red Missing!')
subplot(2,2,3),imshow(b1),title('Green Missing!')
subplot(2,2,4),imshow(c1),title('Blue Missing!')

output 1
Sample 2
CODE 3

% Load an example image


image = imread('cameraman.tif');
image = im2double(image);

% Apply Gaussian noise


gaussian_noisy = imnoise(image, 'gaussian', 0, 0.01);

% Apply Shot noise (Poisson noise)


shot_noisy = imnoise(image, 'poisson');

% Apply Average filter


average_filter = fspecial('average', [3 3]);
average_filtered = imfilter(gaussian_noisy, average_filter);

% Apply Gaussian filter


gaussian_filtered = imgaussfilt(gaussian_noisy, 2);
% Apply Wiener filter
wiener_filtered = wiener2(gaussian_noisy, [5 5]);

% Display the results


figure;
subplot(2, 4, 1), imshow(image), title('Original Image');
subplot(2, 4, 2), imshow(gaussian_noisy), title('Gaussian Noise');
subplot(2, 4, 3), imshow(shot_noisy), title('Shot Noise');
subplot(2, 4, 4), imshow(average_filtered), title('Average Filter');
subplot(2, 4, 5), imshow(gaussian_filtered), title('Gaussian Filter');
subplot(2, 4, 6), imshow(wiener_filtered), title('Wiener Filter');

CODE 2

% Read the original RGB image


RGB = imread('peppers.png');

% Apply two different filters (e.g., a simple averaging filter and a


sharpening filter)
% Define the averaging filter
avg_filter = fspecial('average', [3 3]);
% Define the sharpening filter
sharp_filter = [0 -1 0; -1 5 -1; 0 -1 0];

% Apply the averaging filter


filtered_avg = imfilter(RGB, avg_filter, 'replicate');

% Apply the sharpening filter


filtered_sharp = imfilter(RGB, sharp_filter, 'replicate');

% Display the original and filtered images


figure;
subplot(1, 3, 1), imshow(RGB), title('Original Image');
subplot(1, 3, 2), imshow(filtered_avg), title('Averaging Filtered
Image');
subplot(1, 3, 3), imshow(filtered_sharp), title('Sharpening Filtered
Image');

% Convert RGB to CYK


% First, convert RGB to CMY
C = 1 - double(RGB(:,:,1)) / 255;
M = 1 - double(RGB(:,:,2)) / 255;
Y = 1 - double(RGB(:,:,3)) / 255;

% Calculate K (Black)
K = min(C, min(M, Y));

% Calculate CYK components


C = (C - K) ./ (1 - K);
M = (M - K) ./ (1 - K);
Y = (Y - K) ./ (1 - K);

% Create the CYK image


CYK = cat(3, C, Y, K);
CYK = uint8(CYK * 255); % Scale to 0-255 for display

% Display the CYK image


figure;
imshow(CYK), title('CYK Image');

% Convert RGB to HSI


% Normalize RGB values
R = double(RGB(:,:,1)) / 255;
G = double(RGB(:,:,2)) / 255;
B = double(RGB(:,:,3)) / 255;

% Calculate Intensity
I = (R + G + B) / 3;
% Calculate Saturation
min_RGB = min(min(R, G), B);
S = 1 - (min_RGB ./ I);
S(I == 0) = 0; % Avoid division by zero

% Calculate Hue
theta = acos(0.5 * ((R - G) + (R - B)) ./ sqrt((R - G).^2 + (R - B) .*
(G - B)));
H = zeros(size(I));
H(B <= G) = theta(B <= G);
H(B > G) = 2 * pi - theta(B > G);
H = H / (2 * pi); % Normalize to [0, 1]

% Create the HSI image


HSI = cat(3, H, S, I);
HSI = uint8(HSI * 255); % Scale to 0-255 for display

% Display the HSI image


figure;
imshow(HSI), title('HSI Image');

You might also like