在matlab中将图像分割成窗口

时间:2014-04-16 14:47:14

标签: matlab image-processing

我使用以下决策树来检测图像中的ROI:http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3097782/figure/F7/。第一部分使用32x32窗口使用下面显示的代码扫描整个图像。谁能告诉我如何计算这个窗口内像素的平均强度?感谢

N = 32;
info = repmat(struct, ceil(size(M, 1) / N), ceil(size(M, 2) / N));
for row = 1:N:size(M, 1)%loop through each pixel in the image matrix
    for col = 1:N:size(M, 2)
        r = (row - 1) / N + 1;
        c = (col - 1) / N + 1;

        imgWindow = M(row:min(end,row+N-1), col:min(end,col+N-1));
        largest = max(imgWindow(:));
        [rLarg, cLarg] = find(imgWindow == largest, 1, 'first');

        window(r, c).largest = largest;
        window(r, c).row = rLarg + row - 1;
        window(r, c).col = cLarg + col - 1;
    end
end

1 个答案:

答案 0 :(得分:0)

mean函数计算平均值

average = mean(imgWindow(:));

然后,您可以按照与最近窗口所做的相似的方式保存每个窗口的平均值:

window(r, c).average = average;