フィルターのクリア

how to draw a rectangle to identify character

3 ビュー (過去 30 日間)
ahmed
ahmed 2014 年 3 月 29 日
コメント済み: Rik 2021 年 7 月 14 日
This code to draw a rectangle to identify character that I had found (overlay the template in a target).
[name,path] = uigetfile('*.jpg');
image1 = imread([path,name]);
[name,path] = uigetfile('*.jpg');
image2 = imread([path,name]);
if size(image1,3)==3
image1=rgb2gray(image1);
end
if size(image2,3)==3
image2=rgb2gray(image2);
end
% check which one is target and which one is template using their size
if size(image1)>size(image2)
Target=image1;
Template=image2;
else
Target=image2;
Template=image1;
end
% find both images sizes
[r1,c1]=size(Target);
[r2,c2]=size(Template);
% mean of the template
image22=Template-mean(mean(Template));
%corrolate both images
corrMat=[];
for i=1:(r1-r2+1)
for j=1:(c1-c2+1)
Nimage=Target(i:i+r2-1,j:j+c2-1);
Nimage=Nimage-mean(mean(Nimage)); % mean of image part under mask
corr=sum(sum(Nimage.*image22));
corrMat(i,j)=corr;
end
end

回答 (3 件)

Image Analyst
Image Analyst 2014 年 3 月 29 日
That's a dangerous way to use size(). Looks like someone needs to read Steve's blog on the use of the size function.
Anyway, I'm not sure what your question is. Do you want to draw a rectangle in the overlay above the image? If so, use plot() or rectangle().
  2 件のコメント
Image Analyst
Image Analyst 2014 年 3 月 29 日
編集済み: Image Analyst 2014 年 3 月 29 日
Anyway, you can't find a template in a target by correlation, at least not robustly. Think about it and if you don't know why, ask. You'll need to use normalized cross correlation, as shown in my attached demo.
raha boolat
raha boolat 2021 年 7 月 14 日
It was a wonderful program. Bravo

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


ahmed
ahmed 2014 年 3 月 29 日
編集済み: ahmed 2014 年 3 月 29 日
i want to draw a rectangle in a overlay the full image illuster to identify the character
  1 件のコメント
Image Analyst
Image Analyst 2014 年 3 月 30 日
Invert your image so that the letters are white and then run the normalized cross correlation code I gave you.

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


raha boolat
raha boolat 2021 年 7 月 14 日
編集済み: Rik 2021 年 7 月 14 日
function obj_det(img_name)
f=imread (img_name);
if (size(f,3) >1)
f=rgb2gray(f);
f_bw=~im2bw(f,graythresh(f));
else
f_bw=~im2bw(f,graythresh(f));
end
f_bw=imfill(f_bw,'holes');
s=bwconncomp(f_bw);
imshow(f);
for i=1:s.NumObjects
ind=s.PixelIdxList{i};
[r,c]=ind2sub(size(f),ind);
min_r=min(r,[],1);
max_r=max(r,[],1);
min_c=min(c,[],1);
max_c=max(c,[],1);
hy=max_r - min_r;
hx=max_c - min_c;
rectangle('position',[min_c,min_r,hx,hy],'EdgeColor','r');
end
end
  1 件のコメント
Rik
Rik 2021 年 7 月 14 日
@raha boolat This time I edited your answer for you. Next time, please use the tools explained on this page to make your posts more readable.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by