hslogic_画像二値化処理に基づく新聞セグメンテーションアルゴリズムの簡単な実現

         新聞の異なるニュースの間に境界があるので、問題は、多くの黒い線で区切られた真ん中の画像を黒い線で複数の画像に分割することです。

 

p1 = 0.73;
p2 = 6;
p3 = 3;
p4 = 5;


I1 = imread( 'newspaper.jpg');%画像形式を読み取るRGB
I2 = rgb2gray(I1);%グレースケールに変換

figure(1)
subplot(231)、imshow(I2)%グレースケールを表示

I3 = im2bw(I2、p1);%2値化処理
subplot(232)、imshow(I3)%2値化グラフの表示

SE1 = strel( 'disk'、p2);%構造要素の操作、操作モードはディスク
I4 = imerode(I3、SE1);%画像腐食
サブプロットを実現(233)、imshow(I4)%画像腐食後に画像を表示

SE2 = strel( 'square'、p3);%Structural element operation、the operation mode is square
M1 = imopen(I4、SE2);%Realize image腐食
サブプロット(234)、imshow(M1)%画像腐食後の画像を表示

SE3 = strel( 'square'、p4)%構造要素の操作、操作方法は四角形
I5 = imclose(M1、SE3);%画像の腐食
サブプロットを実現(235)、imshow(I5)%画像の腐食後に画像を表示

I6 = imfill(〜I5、 'holes')%Fill
サブプロット(236)、マージンのimshow(I6)    

[L、n] = bwlabel(I6);         
図(2)
imshow(I1);


for i = 1:n
   
    [r、c] = find(L == i);
    a1(i)= max(r); a2(i)= min(r);
    b1(i)= max(c); b2(i)= min(c);
    w = b1(i)-b2(i); h = a1(i)-a2(i); 
    rectangle( 'Position'、[b2(i)、a2(i)、w、h]、 'LineWidth'、3、 'EdgeColor'、 'b');
    
    b = strcat(int2str(i));
    c = '。jpg';
    str = strcat(b、c);
    imwrite(I1(a2(i):a1(i)、b2(i):b1(i)、1:3)、str、 'jpg');
終わり

おすすめ

転載: blog.csdn.net/ccsss22/article/details/108709004