% Experiment 1: Introduction to MATLAB and Image Processing % (MATLAB Onramp and Image Processing Onramp) clear; close all; clc; %% Part A: MATLAB basics (MATLAB Onramp) x = 0:0.05:2*pi; % row vector using the colon operator y = sin(x); % element-wise function evaluation A = magic(4); % 4 x 4 matrix B = A'; % transpose C = A .* B; % element-wise multiplication fprintf('Size of A : %d x %d\n', size(A, 1), size(A, 2)); fprintf('Sum of column 1 of A: %d\n', sum(A(:, 1))); fprintf('Max element of A.*B : %d\n', max(C(:))); fprintf('Mean of sin(x) : %.4f\n', mean(y)); figure('Name', 'A_matlab_basics'); plot(x, y, 'b-', 'LineWidth', 1.5); hold on; plot(x, cos(x), 'r--', 'LineWidth', 1.5); hold off; grid on; legend('sin(x)', 'cos(x)'); xlabel('x (radians)'); ylabel('Amplitude'); title('Plotting vectors in MATLAB'); %% Part B: Image Processing basics (Image Processing Onramp) rgbImg = imread('peppers.png'); imgInfo = imfinfo('peppers.png'); fprintf('Image size : %d x %d x %d\n', size(rgbImg, 1), size(rgbImg, 2), size(rgbImg, 3)); fprintf('Image class : %s, bit depth %d\n', class(rgbImg), imgInfo.BitDepth); grayImg = rgb2gray(rgbImg); % colour to grayscale adjImg = imadjust(grayImg); % contrast adjustment bwImg = imbinarize(grayImg); % thresholding (Otsu) fprintf('Gray range : [%d %d], after imadjust: [%d %d]\n', ... min(grayImg(:)), max(grayImg(:)), min(adjImg(:)), max(adjImg(:))); fprintf('Foreground pixels in binary image: %.2f %%\n', 100 * mean(bwImg(:))); figure('Name', 'B_image_basics'); subplot(2, 3, 1); imshow(rgbImg); title('RGB image'); subplot(2, 3, 2); imshow(grayImg); title('Grayscale (rgb2gray)'); subplot(2, 3, 3); imshow(adjImg); title('Adjusted (imadjust)'); subplot(2, 3, 4); imhist(grayImg); title('Histogram of gray image'); subplot(2, 3, 5); imhist(adjImg); title('Histogram after imadjust'); subplot(2, 3, 6); imshow(bwImg); title('Binary (imbinarize)');