在矩阵的指定区域中搜索最大值,然后围绕最大值提取矩阵的一部分

时间:2012-08-20 17:24:42

标签: matlab matrix indexing extract region

我正在尝试提取矩阵的特定区域,然后找到该区域内的最大值并提取其周围的值以形成新的9x9矩阵。

到目前为止,我发现这是我认为需要实施的内容:

% extract region
BRegion = B(rowStart:rowEnd, colStart:colEnd);
% find max value and get its index
[value, k] = max(BRegion(:));
[i, j] = ind2sub(size(BRegion), k);
% move indexes to correct spot in matrix 
i = i + rowStart-1;
j = j + colStart-1; 

在具有索引的区域中找到最大值后,如何构建新矩阵,从其周围的9x9区域中取值并使用最大值作为中心?

1 个答案:

答案 0 :(得分:0)

% extract region
rowstart = 300;
rowend = 500;
colstart = 3500;
colend = 4500;
BRegion = B(rowstart:rowend, colstart:colend);

% find max value and get its index
[value, k] = max(BRegion(:)); 
[i, j] = ind2sub(size(BRegion), k);

% move indexes to correct spot in matrix
i = i + rowstart-1;
j = j + colstart-1;

% creates new matrix
new_row_begin = i-4;
new_row_end = i+4;
new_col_begin = j-4;
new_col_end = j+4;

newmat = B(new_row_begin:new_row_end,new_col_begin:new_col_end);