![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/761311/image.png)
How can I design a correlator to detect the character ‘G’ from the google image?
3 ビュー (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/757079/image.jpeg)
0 件のコメント
採用された回答
Image Analyst
2021 年 10 月 8 日
If you know the G is there, you can get a mask for the G letter with the following code, which assumes the G will be the leftmost letter in the image:
rgbImage = imread('google.jpeg');
mask = ~imbinarize(rgb2gray(rgbImage)); % Get letters as foreground.
imshow(mask);
labeledImage = bwlabel(mask); % Give an ID# to each blob.
g = ismember(labeledImage, 1); % Extract blob #1, which will be the G
imshow(g);
If you're not sure if the G is there, then you can use the normalized cross correlation (as in my other answer) to see if it's there or not.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/761311/image.png)
0 件のコメント
その他の回答 (3 件)
Mahesh Taparia
2021 年 10 月 7 日
Hi
The letter 'G' in Google appear to be bigger than the rest of the letter. So 'G' can be selected based on its size. You can use regionprops function to find the bounding box coordinate with maximum area and then draw rectangle on it. For example consider the code below:
a=imread('google.jpeg');
b=rgb2gray(a)<200;
c=regionprops(b,'Area','BoundingBox');
area=zeros(length(c),1);
for i=1:length(c)
area(i)=c(i).Area;
end
[val idx]= max(area);
bbox = c(idx).BoundingBox;
imshow(a);
hold on;
rectangle('Position',bbox)
Hope it helps!
0 件のコメント
Image Analyst
2021 年 10 月 7 日
If you have the G as a template, you can use normalized cross correlation with the function normxcorr2(). See attached example.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/760886/image.png)
0 件のコメント
yanqi liu
2021 年 10 月 8 日
sir,please check the follow code to get some information
clc;
close all;
clear all;
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/757079/image.jpeg');
% get chars
hsv = rgb2hsv(img);
s = mat2gray(hsv(:,:,2));
s = imcomplement(s);
bw = im2bw(s, graythresh(s));
bw = ~bw;
figure; imshow(bw);
% gen G block
figure('Color', 'w'); hold on; axis off;
text(0.5,0.5,'G','FontSize',64);
f = getframe(gcf);
f = frame2im(f);
bw2 = ~im2bw(f);
[r,c] = find(bw2);
bw2 = bw2(min(r):max(r),min(c):max(c));
% make correlator
[L,num] = bwlabel(bw);
stats = regionprops(L);
rc = [];
for i = 1 : num
bwi = imcrop(bw, round(stats(i).BoundingBox));
bwi = imresize(bwi, size(bw2));
rc(i) = corr2(bwi,bw2);
end
% max corr
[~, ind] = max(rc);
figure; imshow(img);
hold on; rectangle('Position', round(stats(ind).BoundingBox), 'EdgeColor', 'r', 'LineWidth', 2, 'LineStyle', '-');
2 件のコメント
Image Analyst
2021 年 10 月 20 日
@Rahul Shah, youi can find the brightest point then get that line. If your correlation image is corrImage, do
maxValue = max(corrImage(:))
[rows, columns] = find(corrImage == maxValue);
verticalProfile = corrImage(:, columns(1));
plot(verticalProfile, 'r-', 'LineWidth', 2);
horizontalProfile = corrImage(rows(1), :);
plot(horizontalProfile, 'b-', 'LineWidth', 2);
ylabel('Correlation Value');
xlabel('Pixel Location')
title('Correlation Profile Through Peak')
grid on;
legend('Vertical', 'Horizontal')
参考
カテゴリ
Help Center および File Exchange で Detection についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!