2016-08-24 7 views
0

イメージのサイズがMxNです。ここでやりたいことは、イメージの1/4サイズのステップサイズを持つウィンドウmxnを作成し、それを左からイメージ内に移動することです底部に右、上、次いでiはイメージ内にmxnウィンドウを移動する

pixel density in a window= Number of white pixels/Total Number of pixels 

、いくつかの固定画素密度のためである画素密度を計算することになるが、私は1または0

ことがウィンドウの中心ピクセルを設定します0.45言うあり私はmatlabで使用できるいくつかの事前定義された関数があります。

更新

私が代わりにあなたがBorderSizeの適切な値を設定することにより、blockprocの非常に単純な関数を使用することができ、ループに入るの次の努力

function result=imagePixelDensity(Image,window,thresh) 
    [WidthI,HeightI]=size(Image); 
    [WidthW,HeightW]=size(window); 
    totalDensity=WidthW*HeightW; 
    stepW=WidhtI/4; 
    for r=1:WidthI 
     for c=1:HeightI 
      if(c+stepW<WidthI && WidhtW+stepW <WidthI) 
       Temp=Image(r:HeightW,c+stepW:WidthW+stepW); 
       dens=sum(Temp(:))/totalDensity; 
       if(dens>=thres) 
         % donot know what to do here like setting or clearing     
         %pixel in a window 
       end 


       stepW=stepW+WidthW; 
      end 
     end 

    end 
end 

答えて

1

を行っています。例は次のとおりです。

mypxden = @(block_struct) ... 
sum(block_struct.data(:))/(size(block_struct.data,1)*size(block_struct.data,2)/4); 
I_proc = blockproc(I,[1,1],mypxden,'BorderSize',[round(((size(I,1)/4)-1)/2),round(((size(I,2)/4)-1)/2)],'TrimBorder',false); 
関連する問題