How to get the both uncontiguous objects in an image as just an object

1 回表示 (過去 30 日間)
i want to loop a word in image, so that i can take every character in that image. but if i use the third dimension of bwlabel as my limit loop, the character like "i" will assume as 2 characters. because it has 2 uncontiguous object in that image. i think i have found how to get all characters of "Nick" by cropped those character automatically. but i confuse how to loop it so i can take every character and compare them with my training data.
Thanks before.
  3 件のコメント
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018 年 12 月 23 日
i pologize for didn't attach the code and testing image before. and also i apologize because my slow response, because i haven't gotten any notification yet in mail.
Here the files are.
the "i" as my example case in above is the ninth character from the left in Adok_karo1_biner.jpg.
thanks for your respone @Image Analyst
Image Analyst
Image Analyst 2018 年 12 月 23 日
Why are you doing edge detection and dilation??? That certainly doesn't make it easier to separate the characters. Don't do that!

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2018 年 12 月 23 日
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
grayImage =imread('Adok_karo1_biner.jpg');
% Show image
figure(1)
h1 = subplot(4, 12, 1:12);
imshow(grayImage);
impixelinfo
title('INPUT IMAGE WITH NOISE')
%% Convert to gray scale
if size(grayImage, 3) == 3 % RGB image
grayImage=rgb2gray(grayImage);
end
%% Convert to binary image
threshold = graythresh(grayImage);
binaryImage = im2bw(grayImage, threshold);
% Remove all object containing fewer than 15 pixels
binaryImage = bwareaopen(binaryImage,15);
imshow(binaryImage);
axis('image', 'on'); % Display tick marks.
title('Binary Image', 'FontSize', fontSize);
% Find horizontal profile
h2 = subplot(4, 12, 13:24);
horizontalProfile = sum(binaryImage, 1);
plot(horizontalProfile, 'b-');
title('Horizontal Profile', 'FontSize', fontSize);
grid on;
% Find dividing lines between the characters.
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
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
drawnow;
% Extract each letter.
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
0000 Screenshot.png
Note that if you have kerning, like with characters 3 and 5, this algorithm won't work and you will have to do a little more work, like label the sub image and if there are two blobs, find their centroids. If there centroids are horizontally separated, then they're two kerned characters and you can nsplit them apart with ismember(). If the centroids are vertically aligned or close to it, then you might consider it as one character that has two parts like an i or j.
  9 件のコメント
Image Analyst
Image Analyst 2018 年 12 月 30 日
You should use ismember() as I showed in my Image Segmentation Tutorial in my File Exchange:
L1 = ismember(L, 1);
L2 = ismember(L, 2);
because I think find() may just return a 1-D array of linear indexes, not an image.
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2019 年 1 月 3 日
thank you Image Analyst it worked perfectly. do you wanna help me to answer my new question sir. the question related with this question. This the link is :
thanks a lot sir.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by