exp1
exp1
Aim- Write a program to read on RGB image and perform various operations on the image.
Theory- An RGB image is a color image composed of three channels: Red (R), Green (G),
and Blue (B). Each channel contains intensity values, and when combined, they represent the
color at each pixel.
Each pixel in an RGB image is represented as a triplet (R,G,B)(R, G, B)(R,G,B), where RRR,
GGG, and BBB are integers (often ranging from 0 to 255 in 8-bit images). Colors are formed
by mixing these three components in varying intensities. This makes RGB images suitable for
tasks that require color recognition, object detection, and segmentation.
In contrast, a grayscale image contains only intensity information, with each pixel representing
a shade of gray, typically ranging from black (0) to white (255). Grayscale images are
computationally simpler and require less memory, making them ideal for tasks like edge
detection, thresholding, and pattern recognition where color information is not critical.
Conversion between RGB and grayscale is often necessary; grayscale images are derived from
RGB by combining the red, green, and blue components using weighted sums based on human
visual sensitivity to different colors, while converting grayscale to RGB involves replicating
the intensity across all three channels. Both RGB and grayscale processing have distinct
applications, with RGB focusing on color-rich tasks and grayscale excelling in structural and
intensity-based analyses.
MATLAB Code:
Clc;
Clear all;
Image = imread(‘C:\Users\Guest\Pictures\ab.jpg’);
R=image(:,:,:1);
G=image(:,:,:2);
B=image(:,:,:3);
P=image;
Subplot(2,3,1);
imshow(image);
title(‘original image-20224112’);
image(:,:,1)=0;
image(:,:,2)=0;
b=image;
subplot(2,3,2);
imshow(image);
title(‘blue component-20224112’);
image =p;
image(:,:,2)=0;
image(:,:,3)=0;
r=image;
subplot(2,3,3);
imshow(image);
title(‘red component-20224112’);
image =p;
image(:,:,1)=0;
image(:,:,3)=0;
g=image;
subplot(2,3,4);
imshow(image);
title(‘green component-20224112’);
grayImage=0.654*double(R)+0.2324double(G)+0.444*double(B);
grayImage=uintB(grayImage);
subplot(2,3,5);
imshow(grayImage);
title(‘gray component-20224112’);
OUTPUT:
Result: RGB features were extracted and displayed from the image and it was successfully
converted to a grayscale image;