0
我有以下Chaning形狀上密度
圖像現在我想做的事情是,我想移動是按比例計算(不完全)到MXN窗口圖像的大小。然後我將窗口在圖像中水平移動,如果我發現一些密集區域(閾值是0.35的常數),我會讓中心像素爲1其他方式爲0.
我有以下matlab中的代碼
function result=imagePixelDensity(Image,thresh)
[WidthI,HeightI]=size(Image);
WidthW=round(0.04*WidthI); % window width
HeightW=round(0.02*HeightI); %window height
if(mod(WidthW,2)~=1) % to make odd dimension
WidthW=WidthW+1;
end
if(mod(HeightW,2)~=1) % to make odd dimension
HeightW=HeightW+1;
end
minNumber=min(WidthW,HeightW); % since height and width could vary so I am selecting lowest
WidthW=minNumber;
HeightW=minNumber;
totalDensity=WidthW*HeightW; % total counts of 1 in a window
colLimit=WidthI-WidthW+1; % since window cannot cover the whole width of Image(as it has its own dimension) so I need to restrict its col movements
rowLimit=HeightI-HeightW+1; % since window cannot cover the whole height of Image(as it has its own dimension) so I need to restrict its row movements
stepRow=0;
stepCol=0;
for r=1:rowLimit
for c=1:colLimit
if(((HeightW+stepRow)<=rowLimit) && (WidthW+stepCol)<=colLimit)
Temp=Image(r:HeightW+stepRow,c:WidthW+stepCol); % get a chunk equal to window size from image
dens=sum(Temp(:))/totalDensity; % calculating density
rowMid=(r+HeightW+stepRow)/2; % row index of center of chunk
colMid=(c+WidthW+stepCol)/2; % col index of center of chunk
if(dens>=thresh)
Image(rowMid,colMid)=1; % making that center pixel to 1 in the original image
else
Image(rowMid,colMid)=0;
end
end
stepCol=stepCol+1;
end
stepRow=stepRow+1;
end
result =Image;
end
結果應該是我標記爲紅色的區域,因爲這些是更密集的區域將變成矩形區域,因爲像素在那裏是1。
但我沒有得到所需的結果(實際上根本沒有發生)。
有人可以指導我在這裏或有更好的想法嗎?
」但我沒有得到所需的結果。「你在做什麼? –
沒有什麼其實......它不是在改變形象,更不用說獲得結果了 –
我真的不知道。你的代碼檢測圖像的哪一部分是「高密度的白色」,當密度很高時,你可以使該區域的1個像素爲白色。那麼,最有可能的是,它已經是白色的了,不是嗎? –