我是一个新手。我有许多DICOM图像。
- 我需要获取所有图像的4个最大像素值及其坐标
- 并自动从每个图像中裁剪128 x 128的4个补丁,保持中心像素为已找到的最大像素之一
- 保存这些补丁
以此方式,我需要从每个像素中提取四个补丁。请告诉我如何做到这一点。
我已经为一个图像编写了此代码,但它没有给我正确的答案:
sortedValues = sort(grayImage, 'descend');
% Get the 4 max values and their coords
for k = 1 : 4
thisValue = sortedValues(k);
% Find where it occurs
[rows, columns] = find(grayImage, thisValue);
% Plot them over the image
for k2 = 1 : length(rows)
thisRow = rows(k2);
thisColumn = columns(k2);
plot(thisColumn, thisRow, 'r+');
hold on;
text(thisColumn, thisRow, num2str(k));
% Crop into a new image
row1 = thisRow - 64;
row2 = row1 + 127;
col1 = thisColumn - 64;
col2 = col1 + 127;
subImage = grayImage(row1:row2, col1:col2);
% Now do something with subimage....
end
end
请帮忙。