clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
grayImage =imread('Adok_karo1_biner.jpg');
figure(1)
h1 = subplot(4, 12, 1:12);
imshow(grayImage);
impixelinfo
title('INPUT IMAGE WITH NOISE')
if size(grayImage, 3) == 3
grayImage=rgb2gray(grayImage);
end
threshold = graythresh(grayImage);
binaryImage = im2bw(grayImage, threshold);
binaryImage = bwareaopen(binaryImage,15);
imshow(binaryImage);
axis('image', 'on');
title('Binary Image', 'FontSize', fontSize);
h2 = subplot(4, 12, 13:24);
horizontalProfile = sum(binaryImage, 1);
plot(horizontalProfile, 'b-');
title('Horizontal Profile', 'FontSize', fontSize);
grid on;
props = regionprops(horizontalProfile == 0, 'Centroid');
xyCentroids = [props.Centroid];
dividingLines = xyCentroids(1:2:end)
for k = 1 : length(dividingLines)
thisX = dividingLines(k);
line(h1, [thisX, thisX], ylim(h1), 'Color', 'r');
line(h2, [thisX, thisX], ylim(h2), 'Color', 'r');
end
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
drawnow;
fontSize = 12;
for k = 1 : length(dividingLines) - 1
thisX = round(dividingLines(k));
nextX = round(dividingLines(k+1));
subplot(4, 12, 24 + k);
thisLetter = binaryImage(:, thisX:nextX);
imshow(thisLetter);
caption = sprintf('Letter #%d', k);
title(caption, 'FontSize', fontSize);
end
Best Answer