Detect letters in an image
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey!
I have a text image from where I want to detect the letters 'y' by:
- select one morphological operation for the purpose
- design the corresponding structuring element
- apply the filter to the image once
- calculate the skeleton of the detected letter
And I really have no idea how can I do this. Can someone please help? The input image is 'text.png' from matlab
Thank you in advance!
0 Kommentare
Antworten (1)
Rishabh Singh
am 4 Jan. 2022
Hey,
clear all
close all
% Read in image
I = imread('textsample.png');
I = rgb2gray(I);
% Have user select a section of the image and create template
a_template = imcrop(I);
figure
imshow(a_template)
% Cross-correlate the image with the template
Xcorr = normxcorr2(a_template, I);
% Threshold the image
t_Xcorr = graythresh(Xcorr);
Xcorr_threshold = Xcorr > 0.7;
figure
imshow(Xcorr_threshold);
% Dim of the template and image are needed for drawing boxes and loops
temp_dim = size(a_template);
I_dim = size(I);
y_len = temp_dim(1); x_len = temp_dim(2);
% Find the blods in the thresholded image
L = bwlabel(Xcorr_threshold);
blobs = regionprops(L);
% Draw red box around all the centroids of the blobs
figure
imshow(I)
for k = 1:length(blobs)
y1 = blobs(k).Centroid(2) - y_len/2; x1 = blobs(k).Centroid(1) - x_len/2;
pos_vec = [x1-x_len/2 y1-y_len/2 temp_dim(2) temp_dim(1)];
rectangle('Position', pos_vec, 'EdgeColor', 'r');
drawnow;
end
% Display the number of a's
text(175,100, "There are: " + length(blobs) + " a's", 'FontSize', 14, 'color', 'r')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!