如何在Matlab中进行字符分割

发布于 2024-10-21 19:51:12 字数 1566 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜访吸血鬼 2024-10-28 19:51:12

Regionprops 可能适合你。如果你拿这个样本车牌。

sample

您可以使用像这样的小脚本来剪切对象。抱歉,我只是很快地把它拼凑在一起,但它给了你一个想法。

clear all;
close all;
I = imread('plate.jpg');
BW = im2bw(I, 0.9);
BW = ~BW;


stats = regionprops(BW);
for index=1:length(stats)
    if stats(index).Area > 200 && stats(index).BoundingBox(3)*stats(index).BoundingBox(4) < 30000
    x = ceil(stats(index).BoundingBox(1))
    y= ceil(stats(index).BoundingBox(2))
    widthX = floor(stats(index).BoundingBox(3)-1)
    widthY = floor(stats(index).BoundingBox(4)-1)
    subimage(index) = {BW(y:y+widthY,x:x+widthX,:)}; 
    figure, imshow(subimage{index})
    end
end

这将输出像

A

和这个

dog

你仍然需要确定它是否真的是一封信。注意,脚本会输出很多图像(大约 30 或 40 个)

regionprops might work for you. If you take this sample license plate.

sample

You could use a little script like this to cut out objects. Sorry, I just typed it together really quickly, but it gives you an idea.

clear all;
close all;
I = imread('plate.jpg');
BW = im2bw(I, 0.9);
BW = ~BW;


stats = regionprops(BW);
for index=1:length(stats)
    if stats(index).Area > 200 && stats(index).BoundingBox(3)*stats(index).BoundingBox(4) < 30000
    x = ceil(stats(index).BoundingBox(1))
    y= ceil(stats(index).BoundingBox(2))
    widthX = floor(stats(index).BoundingBox(3)-1)
    widthY = floor(stats(index).BoundingBox(4)-1)
    subimage(index) = {BW(y:y+widthY,x:x+widthX,:)}; 
    figure, imshow(subimage{index})
    end
end

This will output images like

A

and this

dog

You still have to decide if it really is a letter. Be careful, the script will output a lot of images (about 30 or 40)

温馨耳语 2024-10-28 19:51:12

你可以尝试这个代码(这不是我的)

% This is a program for extracting objects from an image. Written for vehicle number     plate segmentation and extraction
% Authors : Jeny Rajan, Chandrashekar P S
% U can use attached test image for testing
% input - give the image file name as input. eg :- car3.jpg
clc;
clear all;
k=input('Enter the file name','s'); % input image; color image
im=imread(k);
im1=rgb2gray(im);
im1=medfilt2(im1,[3 3]); %Median filtering the image to remove noise%
BW = edge(im1,'sobel'); %finding edges 
[imx,imy]=size(BW);
msk=[0 0 0 0 0;
 0 1 1 1 0;
 0 1 1 1 0;
 0 1 1 1 0;
 0 0 0 0 0;];
B=conv2(double(BW),double(msk)); %Smoothing  image to reduce the number of connected     components
L = bwlabel(B,8);% Calculating connected components
mx=max(max(L))
% There will be mx connected components.Here U can give a value between 1 and mx for L     or in a loop you can extract all connected components
% If you are using the attached car image, by giving 17,18,19,22,27,28 to L you can     extract the number plate completely.
[r,c] = find(L==17);  
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy); 
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
figure,imshow(im);
figure,imshow(im1);
figure,imshow(B);
figure,imshow(n1,[]);

you can try this code(it's not mine)

% This is a program for extracting objects from an image. Written for vehicle number     plate segmentation and extraction
% Authors : Jeny Rajan, Chandrashekar P S
% U can use attached test image for testing
% input - give the image file name as input. eg :- car3.jpg
clc;
clear all;
k=input('Enter the file name','s'); % input image; color image
im=imread(k);
im1=rgb2gray(im);
im1=medfilt2(im1,[3 3]); %Median filtering the image to remove noise%
BW = edge(im1,'sobel'); %finding edges 
[imx,imy]=size(BW);
msk=[0 0 0 0 0;
 0 1 1 1 0;
 0 1 1 1 0;
 0 1 1 1 0;
 0 0 0 0 0;];
B=conv2(double(BW),double(msk)); %Smoothing  image to reduce the number of connected     components
L = bwlabel(B,8);% Calculating connected components
mx=max(max(L))
% There will be mx connected components.Here U can give a value between 1 and mx for L     or in a loop you can extract all connected components
% If you are using the attached car image, by giving 17,18,19,22,27,28 to L you can     extract the number plate completely.
[r,c] = find(L==17);  
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy); 
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end % Storing the extracted image in an array
figure,imshow(im);
figure,imshow(im1);
figure,imshow(B);
figure,imshow(n1,[]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文