0% found this document useful (0 votes)
2 views4 pages

MCA LAB Programs

Uploaded by

Nitesh Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

MCA LAB Programs

Uploaded by

Nitesh Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Increase the Brightness of an image


clc;
clear;
close all;

% Read image
img = imread('C:/Users/upasana singh/Downloads/[Link]');

bright_img = img + 50;


imshow(bright_img);
title('Brightness Increased');

2. Rotate image by 180 degrees


clc;
clear;
close all;

% Read image
img = imread('C:/Users/upasana singh/Downloads/[Link]');

% Rotate image by 180 degrees


rot_img = imrotate(img, 180);

% Display
figure;
imshow(img);
title('Original Image');

figure;
imshow(rot_img);
title('Image Rotated by 180 Degrees');

3. Image Flip (Horizontal & Vertical)


clc;
clear;
close all;

% Read image (grayscale or color)


img = imread('C:/Users/upasana singh/Downloads/[Link]');

% Show original image


figure;
imshow(img);
title('Original Image');

% ----------------------------------
% Horizontal Flip (Left ↔ Right)
h_flip = fliplr(img);

figure;
imshow(h_flip);
title('Horizontally Flipped Image');

% ----------------------------------
% Vertical Flip (Top ↔ Bottom)
v_flip = flipud(img);

figure;
imshow(v_flip);
title('Vertically Flipped Image');

4. Perform image sampling and quantization on grayscale images


clc;
clear;
close all;
% ------------------------------------------------
% STEP 1: Read image
img = imread('C:/Users/upasana singh/Downloads/[Link]');

% Force grayscale if image is RGB


if ndims(img) == 3
img = rgb2gray(img);
end

% Convert to double for calculations


img = double(img);

% Display original grayscale image


figure;
imshow(uint8(img));
title('Original Grayscale Image');

% ------------------------------------------------
% STEP 2: Image Sampling (Downsampling)
% Taking every 5th pixel
sampled_img = img(1:2:end, 1:2:end);

figure;
imshow(uint8(sampled_img));
title('Sampled Grayscale Image');

% ------------------------------------------------
% STEP 3: Image Quantization
L = 16; % Number of gray levels
step = 256 / L;
quantized_img = floor(img / step) * step;

% ------------------------------------------------
% STEP 4: Sampling + Quantization
sampled_quantized = floor(sampled_img / step) * step;

figure;
imshow(uint8(sampled_quantized));
title('Sampled + Quantized Grayscale Image');

clc;
clear;
close all;

% ------------------------------------------------
% STEP 1: Read COLOR image
img = imread('C:/Users/upasana singh/Downloads/[Link]');

% Display original color image


figure;
imshow(img);
title('Original Color Image');

% Convert image to double for calculations


img = double(img);

% ------------------------------------------------
% STEP 2: Image Sampling (Downsampling)
% Taking every 5th pixel from each channel

R_s = img(1:5:end, 1:5:end, 1);


G_s = img(1:5:end, 1:5:end, 2);
B_s = img(1:5:end, 1:5:end, 3);

% Combine sampled channels


sampled_color = cat(3, R_s, G_s, B_s);

figure;
imshow(uint8(sampled_color));
title('Sampled Color Image');

% ------------------------------------------------
% STEP 3: Image Quantization
L = 18; % Number of levels
step = 256 / L;

R_q = floor(img(:,:,1) / step) * step;


G_q = floor(img(:,:,2) / step) * step;
B_q = floor(img(:,:,3) / step) * step;

quantized_color = cat(3, R_q, G_q, B_q);

% ------------------------------------------------
% STEP 4: Sampling + Quantization
R_sq = floor(R_s / step) * step;
G_sq = floor(G_s / step) * step;
B_sq = floor(B_s / step) * step;

sampled_quantized_color = cat(3, R_sq, G_sq, B_sq);

figure;
imshow(uint8(sampled_quantized_color));
title('Sampled + Quantized Color Image');

You might also like