clc; close all; for l = 2:21 sum=0; % l=9; grayImage = strcat('e_images_', num2str(l), '.jpg'); grayImage=imread(grayImage); fontSize = 10; maxRows = 0; maxCols = 0; for k = 1 : l % read images..... [rows, columns, numberOfSlices] = size(grayImage); if rows > maxRows maxRows = rows; end if columns > maxCols maxCols = columns; end end for k = 1:l [rows, columns, numberOfColorBands] = size(grayImage); if numberOfColorBands > 1 grayImage = rgb2gray(grayImage); end figure(1); subplot(2, 2, 1); imshow(grayImage, []); title('Original Grayscale Image', 'FontSize', fontSize); end %% Extract left half and display histogram middleColumn = floor(columns/2); leftHalfImage = grayImage(:,1:middleColumn); T = adaptthresh(leftHalfImage,0.5,'ForegroundPolarity','dark'); binaryImage1= imbinarize(leftHalfImage,T); figure(1); subplot(2, 2, 2); imshow(binaryImage1, []); title('left half', 'FontSize', fontSize); %% Extract right half and display histogram middleColumn = floor(columns/2); rightHalfImage = grayImage(:, middleColumn+1:end); T = adaptthresh(rightHalfImage,0.5,'ForegroundPolarity','dark'); binaryImage2= imbinarize(rightHalfImage,T); figure(1); subplot(2, 2, 3); imshow(binaryImage2, []); title('right half', 'FontSize', fontSize); end