Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

I want to segment the word which is between the black color . i could'd by this code help please.

1 visualización (últimos 30 días)
close all;
clear all;
clc;
im=imread('Segmented_line1.jpg');%read the image
figure, imshow(im);
bw=im2bw(im);%convert the image im into binary(black and white)
a=~bw;
figure, imshow(a);
b=sum(a,1);
% Measure lengths of all "0" regions.
measurements = regionprops(b == 0, 'Area', 'PixelIdxList');
% Get indexes of those regions that are >= 20 in length.
fiveLongRegions = find([measurements.Area] >= 20);
theIndexes = vertcat(measurements(fiveLongRegions).PixelIdxList);
c=a;
c(:,theIndexes)=1;
figure, imshow(c);
e=~c;
figure, imshow(e);
[x,y]=size(e);
mat1=sum(e,1);
mat2=x-mat1;%subtract each element of the sum matrix(mat1) from the width length(no. of columns)
mat3=mat2~=0;
mat4=diff(mat3);
index1=find(mat4);
[q,w]=size(index1);%size of index2 matrix is q*w
kap=1;
lam=1;
iii=1;
ii=1;
while kap<((q/2)+1);%number of loops=number of lines
k=1;
mat5=([]);
for j=(index1(lam)+1):1:index1(lam+1)
mat5(k,:)=e(j,:); %store the line segmented matrix
k=k+1;
end
mat6=sum(mat5,2); %sum the elements of the line segmented matrix columnwise
mat7=(index1(lam+1)-index1(lam))-mat6; %subtract each element of the sum matrix(mat6) from the height length(no. of rows)
mat8=mat7~=0;
mat9=diff(mat8);
index2=find(mat9);
[z,r]=size(index2);
nm=rectangle('position',[index1(1)+1,index1(iii),index2(r)-index2(1),index1(iii+1)-index1(iii)+1]);
set(nm,'edgecolor','r')
lam=lam+2;
kap=kap+1;
iii=iii+2;
file_name=sprintf('Segmented_line%d.jpg',ii);
imwrite(mat5,file_name,'tif');
ii=ii+1;
end
input image:
segmented by black pixel:
i want to save words which are segmented by the black pixels.

Respuestas (1)

Image Analyst
Image Analyst el 23 de Mayo de 2014
See my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. It does that. All you have to do is to change the sign of the threshold to segment black regions instead of bright regions, and change the filename of course.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by