how to make line and drawing line in image
조회 수: 2 (최근 30일)
이전 댓글 표시
i try to make line between column in an image..first step i must find in column 1,in row what the first black pixel,and in row what the last black pixel in column 1...step 2 after i found the coordinat, i try to find the average which is the formula : (pixel black first+pixel black last)/2..and i will find the value..and then i will looping this unto the end of column that i have...if the task finished, i try to connected coordinat 1-2-3-4 until the last pixel..is there anybody can help me ?
this is the code :
baca = imread('88.bmp');
% %%========================pre processing===============================
% %convert to binary
glurus4=im2double(baca);
cannyawal = im2bw(glurus4,graythresh(glurus4));
cannyawal=~cannyawal
% figure,imshow (bacabwlurus4), title ('Citra black and white dari tulisan
garis dasar lurus');
%%*************Edge Detection*************************
% cannyawal = edge (bacabwlurus4,'canny');
% figure,imshow (cannyawal), title ('Citra tulisan canny');
% %%******************
[baris kolom] = size(cannyawal);
for kolom1=1:kolom
for baris1=1:baris
if cannyawal(baris1,kolom1)==1
bataskanan=kolom1;
end
end
end
for kolom2=kolom:-1:1
for baris2=1:baris
if cannyawal(baris2,kolom2)==1
batas_kiri=kolom2;
end
end
end
for baris3=1:baris
for kolom3=1:kolom
if cannyawal(baris3,kolom3)==1
batas_bawah=baris3;
end
end
end
for baris4=baris:-1:1
for kolom4=1:kolom
if cannyawal(baris4,kolom4)==1
batas_atas=baris4;
end
end
end
height=((batas_bawah-batas_atas));
width=((bataskanan-batas_kiri));
Gamcrop = imcrop(cannyawal,[batas_kiri batas_atas width height]);%%position
vector, [xmin ymin width height].
figure,imshow (Gamcrop), title ('Citra setelah proses Crop');
GbrAkhir =imresize(Gamcrop,[50,20]);
[x y] = size(GbrAkhir) ;
for c=1:1:y
for baris1=x:-1:1
for kolom1=c
if GbrAkhir(baris1,kolom1)==1
pixel_1_awal=baris1;
end
end
end
for baris2=1:x
for kolom2=c
if GbrAkhir(baris2,kolom2)==1
pixel_1_akhir=baris2;
end
end
end
% pixel_1_awal
% pixel_1_akhir
rata_rata(c) = [pixel_1_akhir+pixel_1_awal]/2;
% m(rata_rata,:)=[x y]
z=ceil(rata_rata);
if GbrAkhir(baris1,kolom1)~=1
pixel_1_awal=0;
end
if GbrAkhir(baris2,kolom2)~=1
pixel_1_akhir=0;
end
end
[r u] =size(z);
for i=1:u
input_uji_88=z(1:1:i);
end
uu=[21,30,25,26,33,31,35,32,37,0,34,39,41,42,0,38,0,0,42,46;]
hold on
M = size(uu,1);
N = size(uu,2);
for k = 1:1:M
xx = [1 N];
yy = [k k];
plot(xx,yy,'Color','w','LineStyle','-');
plot(xx,yy,'Color','k','LineStyle',':');
end
for k = 1:1:N
xx = [k k];
yy = [1 M];
plot(xx,yy,'Color','w','LineStyle','-');
plot(xx,yy,'Color','k','LineStyle',':');
end
hold off
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!