Add second year
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
second/semester2/CT248/Assignments/Assignment-04/Figure_1.png
Normal file
BIN
second/semester2/CT248/Assignments/Assignment-04/Figure_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 228 KiB |
@ -0,0 +1,15 @@
|
||||
clear;
|
||||
eng1 = imread("Engineering-Building.jpg");
|
||||
eng1_gs = pic2grayscale(eng1);
|
||||
eng1_gs_inv = transform_pic(eng1_gs);
|
||||
eng1_gs_bin_50 = transform_threshold(eng1_gs,50);
|
||||
eng1_gs_bin_75 = transform_threshold(eng1_gs,75);
|
||||
eng1_gs_bin_100 = transform_threshold(eng1_gs,100);
|
||||
|
||||
% plotting images
|
||||
subplot(3,2,1),imshow(eng1),title("Original Picture");
|
||||
subplot(3,2,2),imshow(eng1_gs),title("Greyscale");
|
||||
subplot(3,2,3),imshow(eng1_gs_inv),title("Inverted Greyscale");
|
||||
subplot(3,2,4),imshow(eng1_gs_bin_50),title("Binary Threshold = 50");
|
||||
subplot(3,2,5),imshow(eng1_gs_bin_75),title("Binary Threshold = 75");
|
||||
subplot(3,2,6),imshow(eng1_gs_bin_100),title("Binary Threshold = 100");
|
@ -0,0 +1,17 @@
|
||||
function [returnImg] = pic2grayscale(img)
|
||||
% which uses the NTSC Standard transformation to convert RGB to grayscale.
|
||||
%0.2989 * R + 0.5870 * G + 0.1140 * B
|
||||
|
||||
% img to be returned
|
||||
returnImg = zeros(size(img,1), size(img, 2));
|
||||
|
||||
% looping through the RGB image and calculating the grayscale value for
|
||||
% each pixel in the corresponding returnImg
|
||||
for i = 1:size(img,1)
|
||||
for j = 1:size(img,2)
|
||||
returnImg(i,j) = (0.2989 * img(i,j,1)) + (0.5870 * img(i,j,2)) + (0.1140 * img(i,j,3));
|
||||
end
|
||||
end
|
||||
|
||||
returnImg = uint8(returnImg);
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
function [img] = transform_pic(img)
|
||||
% function which converts a 255 colour code to 0, 254 to 1, etc, and 0 to
|
||||
% 255.
|
||||
img = 255 - img;
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
function [img] = transform_threshold(img, threshold)
|
||||
% function which converts the picture to binary format where any value
|
||||
% above the threshold is white (1), and all values equal to or below are
|
||||
% black (0).
|
||||
|
||||
% looping through each element in the matrix, and setting it to 1 if
|
||||
% above the threshold, 0 otherwise
|
||||
for i = 1:numel(img)
|
||||
if img(i) > threshold
|
||||
img(i) = 1;
|
||||
else
|
||||
img(i) = 0;
|
||||
end
|
||||
end
|
||||
|
||||
% casting the matrix to type logical once each element is either 1 or 0
|
||||
img = logical(img);
|
||||
end
|
Reference in New Issue
Block a user