开发者

Code explanation - Matlab

this code suppose to perform character segmentation from an image in Matlab. the code was given to me by Lucas, so thanks Lucas.

the problem is that I want to understand precisely how the character segmentation is done, I'm don't want to use it before I understand it.

can anyone explain it for me... thanks.

Lucas code:

    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)     
        wid开发者_如何学编程thY = floor(stats(index).BoundingBox(4)-1)     
        subimage(index) = {BW(y:y+widthY,x:x+widthX,:)};      
        figure, imshow(subimage{index})    
    end 
end

link: how to perform character segmentation in Matlab


clear all; % clear out workspace memory
close all; % close all figures
I = imread('plate.jpg'); % load image jpg into I
BW = im2bw(I, 0.9); % convert color image to black and white image
BW = ~BW;   % swap black and white
stats = regionprops(BW); % compute 'Area', 'Centroid', and 'BoundingBox' measurements.
% The regionprops operation is what "cuts up" the image into possible pieces of interest.
% You will need to develop your own code for processing.
for index=1:length(stats)
    % if the stats of the region meet a certain criteria
    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)
    % extract a subimage from the original image and show it.
    subimage(index) = {BW(y:y+widthY,x:x+widthX,:)};      
    figure, imshow(subimage{index})    
end 

As suggested by Eugene, review the link provided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜