您现在的位置是:主页 > news > 青岛制作网站/网站快速收录的方法
青岛制作网站/网站快速收录的方法
admin2025/5/19 22:05:04【news】
简介青岛制作网站,网站快速收录的方法,胶南网站建设价格,代理记账网站怎么做regionprops通过按列主要顺序查找blob来运行. regionprops不按行主要顺序运行,这正是您要寻找的.列主要排序源自MATLAB本身,因为按列主要顺序操作是本机行为.此外,使用find / bwlabel的逻辑也以列主格式运行,因此在尝试以行主格式显示字符时,必须记住这两点.因此,一种简单的方法…
regionprops通过按列主要顺序查找blob来运行. regionprops不按行主要顺序运行,这正是您要寻找的.列主要排序源自MATLAB本身,因为按列主要顺序操作是本机行为.此外,使用find / bwlabel的逻辑也以列主格式运行,因此在尝试以行主格式显示字符时,必须记住这两点.
因此,一种简单的方法是修改for循环,以便您可以按行而不是按列访问结构.对于您的示例图像,描绘的字符顺序如下:
1 3 5
2 4 6
您需要按以下顺序访问结构:[1 3 5 2 4 6].因此,您将更改for循环以访问此新数组,您可以像这样创建这个新数组:
ind = [1:2:numel(stats) 2:2:numel(stats)];
完成后,只需修改for循环即可访问ind中的值.为了使代码完全可重复,我将直接从StackOverflow读取您的图像,并在文本为黑色时反转图像.文本需要为白色才能使blob分析成功:
%// Added
clear all; close all;
BinaryImage = ~im2bw(imread('http://s4.postimg.org/lmz6uukct/plate.jpg'));
[L Ne]=bwlabel(BinaryImage);
stats=regionprops(L,'BoundingBox');
cc=vertcat(stats(:).BoundingBox);
aa=cc(:,3);
bb=cc(:,4);
figure;
ind = [1:2:numel(stats) 2:2:numel(stats)]; %// Change
for n = ind %// Change
if (aa(n)/bb(n) >= 0.2 && aa(n)/bb(n)<= 1.25)
[r,c] = find(L==n);
n1=BinaryImage(min(r):max(r),min(c):max(c));
imshow(~n1);
pause(0.5)
end
end
警告
上面的代码假定只有两行字符.如果你有更多,那么显然指定的索引将不起作用.
如果你想让它适用于多行,那么我要写的这个逻辑假定文本是水平的而不是一个角度.简单地说,你将循环,直到你用完结构,在循环的开始,你会搜索具有我们没有的blob左上角最小(x,y)坐标的blob处理.找到它之后,搜索在此源y坐标的某个阈值范围内的所有y坐标,并获取这些位置处的索引.你会重复这个,直到你的结构耗尽为止.
像这样的东西:
thresh = 5; %// Declare tolerance
cc=vertcat(stats(:).BoundingBox);
topleft = cc(:,1:2);
ind = []; %// Initialize list of indices
processed = false(numel(stats),1); %// Figure out those blobs that have been processed
while any(~processed) %// While there is at least one blob to look at...
%// Determine the blob that has the smallest y/row coordinate that's
%// unprocessed
cc_proc = topleft(~processed,:);
ys = min(cc_proc(:,2));
%// Find all blobs along the same row that are +/-thresh rows from
%// the source row
loc = find(abs(topleft(:,2)-ys) <= thresh & ~processed);
%// Add to list and mark them off
ind = [ind; loc];
processed(loc) = true;
end
ind = ind.'; %// Ensure it's a row
然后,您将使用ind变量并将其与for循环一起使用,就像之前一样.