【问题标题】:dicom images min max pixels and locationsdicom 图像最小最大像素和位置
【发布时间】:2017-03-16 07:36:47
【问题描述】:

我是新来的。我有许多 dicom 图片。

  1. 我需要获取所有图像的 4 个最大像素值及其坐标
  2. 并自动从每个图像中裁剪 128 x 128 4 个补丁,使中心像素保持为已找到的最大像素之一
  3. 保存补丁

这样我需要从每个像素中提取四个补丁。请告诉我该怎么做。

我已经为一张图片制作了这段代码,但它没有给我正确的答案:

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

请帮帮我。

【问题讨论】:

  • 尝试添加示例图像并显示您得到的答案以及错误的原因。

标签: image matlab crop dicom minmax


【解决方案1】:

按照您的代码,这是最直接的方法。请注意,我在此过程中进行了一些更正和改进:

imshow(grayImage);
hold on;   % only needed once

% corrected to sort the entire image grayImage(:), not just column-by-column
% sortedValues not used here, but left for future use
[sortedValues, sortedIndices] = sort(grayImage(:), 'descend');

for k = 1:4
   [m,n] = size(grayImage);
   [r,c] = ind2sub([m,n], sortedIndices(k));
   plot(c, r, 'r+');
   text(c, r, num2str(k));
   row1 = max(r - 64, 1);   % make sure rows/columns don't fall outside image
   row2 = min(r + 63, m);
   col1 = max(c - 64, 1);
   col2 = min(c + 63, n);
   subImage = grayImage(row1:row2, col1:col2);
   % Now do something with subimage...
end

hold off;

这使用sort 的第二个输出来获取最大像素的索引,然后将这些索引传递给ind2sub 以获取行/列号。

【讨论】:

    【解决方案2】:

    您可以在 bash 中使用 vipsImageMagick

    执行此操作
    #!/bin/bash
    # Convert DICOM image to PNG for vips
    convert image.dcm image.png
    
    # Use vips to get x and y of 4 maximum pixel locations
    { read line; read -a x <<< "$line"
      read line; read -a y <<< "$line"
      read line; } < <(vips im_maxpos_vec image.png 4)
    
    # Now crop them out as centres of 128x128 boxes
    i=0
    for index in "${!x[@]}"; do
       cx=${x[index]}
       cy=${y[index]}
       ((a=cx-64))
       ((b=cy-64))
       echo Cropping from $cx,$cy to sub-${i}.png
       convert image.png -crop 128x128+${cx}+${cy} +repage sub-${i}.png
       ((i=i+1))
    done
    

    如有必要,我可能会删除对 vips 的需求。

    【讨论】:

    • 我在用matlab,请问你能说出什么是bash、vips、ImageMagic吗?
    • 它们是一组极其强大、极其灵活、免费的开源图像处理工具,但如果您不了解它们,请不要担心 - 只需将您的问题标记为 Matlab 和我我相信其他人会帮助你。
    猜你喜欢
    • 2019-12-08
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 2011-02-03
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多