-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw7_9.m
34 lines (27 loc) · 867 Bytes
/
hw7_9.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [img_corrected] = hw7_9(img_path, gamma)
% This function performs gamma correction on an image using for-loops
% Load the image
img = imread(img_path);
% Convert image pixel values to the range [0,1]
img_norm = double(img) ./ 255;
% Get the dimensions of the image
[row, col] = size(img_norm);
% Initialize the corrected image
img_corrected = zeros(row, col);
% Loop through each pixel in the image and calculate its corrected value
for i = 1:row
for j = 1:col
img_corrected(i,j) = img_norm(i,j) .^ gamma;
end
end
% Scale the corrected image back to the range [0,255] and round to nearest integer
img_corrected = round(img_corrected .* 255);
% Display the original and corrected images side by side
figure;
subplot(1,2,1);
imshow(img);
title('Original Image');
subplot(1,2,2);
imshow(img_corrected);
title('Gamma-Corrected Image');
end