【问题标题】:Create a loop in order to create freehand ROIs创建一个循环以创建手绘 ROI
【发布时间】:2016-08-16 04:41:48
【问题描述】:

我完成了以下代码,我从电影中导入一帧,转换为灰度并徒手绘制感兴趣的区域。然后我使用 Chan-Vese 区域填充来获取我感兴趣的区域并基于此创建蒙版。我终于可以得到我正在寻找的二进制图像,在代码中称为 BW3。现在这是愚蠢的部分。如何创建一个循环以使代码运行(加载第 1 到 58 帧),向我展示第 1 帧的灰度图像,让我绘制感兴趣的区域,然后创建并保存最终的二进制图像 BW3? 问候, J

    % Select Initial Image
for n = 5:87
frame = read(obj,n);


%Isolate the Blade
imggray = rgb2gray(frame);
h_im=imshow(imggray);

%Region of interest
% r = imrect(gca,[646,188,18,-648]);
% BW2 = createMask(r,h_im);

hROI = imfreehand(gca);
Position = getPosition(hROI);
BW2 = createMask(hROI);

%Get blade Binary

BW3 = activecontour(imggray, BW2, 1000, 'Chan-Vese');

% Fill Holes
BW3 = imfill(BW3, 'holes');

% Form masked image from input image and segmented image.
maskedImage = h_im;
maskedImage(~BW3) = 0;

%Save binary frame
filename = sprintf('C:..........\\binaryimage%d.png', n);
imwrite(BW3,filename,'png');
end

【问题讨论】:

    标签: matlab loops binary mask


    【解决方案1】:

    假设您的帧数有限(即最多 58 个),您可以使用 for 循环来完成此操作。在您的代码中,您必须更改初始图像代码,以便它与循环一起迭代。

    for counter=1:58
        frame=read(obj,counter); 
        imwrite(frame,strcat('frame',num2str(counter),'.png'))
        .....% the remainder of your code likely remains unchanged.
    end
    

    在编写结果时,您可能需要将其放入某种结构中,以便循环遍历,除非您在每个循环中将结果写入文件。

    【讨论】:

    • 嗨,我自己做到了。请参阅修改后的代码。出于某种原因,我只是迷失了一点,无法弄清楚。再次感谢
    猜你喜欢
    • 1970-01-01
    • 2016-03-10
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 2015-09-05
    • 2022-07-12
    • 2015-01-24
    相关资源
    最近更新 更多