通过蒙版在图像上应用功能 [英] To apply a function through a mask on an image
问题描述
我在impoly('Closed', true)
上在图片上创建了一个封闭区域,最后在Matlab命令行中标记了遮罩BW = createMask(h)
的区域之后.
在图中为掩膜标记点之前的初始命令
I create a closed region on a picture by impoly('Closed', true)
and lastly after marking the area for the mask BW = createMask(h)
in Matlab commandline.
Initial commands before marking points for the mask in the figure
imshow('contour.png');
h = impoly('Closed',true);
在这里,我在下面使用了 nkjt的答案. 要通过功能 conditionalRemoval(图像,区域)
Here, I used nkjt's answer below. The picture to be filtered by the function conditionalRemoval(image, area)
然后,我跑步
image = imread('contour.png');
areaLazyRemoval = BW;
image = conditional_removal(image, areaLazyRemoval);
我现在有了掩码和图片. 我应该将功能 conditional_removal 应用于他们.
I now have the mask and the picture. I should apply the function conditional_removal to them.
如何立即使用此蒙版并将功能应用于其标记的区域?
我的函数 conditional_removal 的伪代码是
function [ image ] = conditional_removal( image, areaLazyRemoval )
% dim image 794 x 1001 x 3 uint
% dim areaLazyRemoval 794 x 1001 logical
image(:,:,1) .* areaLazyRemoval; % TODO wrong operator here!
% all pixels marked by logical ones in areaLazyRemoval should get lazyRemoval applied
% else greedyRemoval so zero
%
end
%%%%%%%%%%%%%%%%%%%%%%%
% lazy removal function
% so remove by 50% chance the thing
function pixel = lazyRemoval(pixel)
if randn > 0
pixel = 0;
end
% TODO how to apply pixel-wise removal to the logical matrix and image?
如何通过逻辑矩阵遮罩对图像进行逐像素去除?
推荐答案
为此:
impoly>生成数据>函数createfigure1
impoly > Generate Data > function createfigure1
您的意思是说在打了无礼后,您进入图形窗口并选择"Generate Code"(生成代码)?它将创建一个函数createfigure
-但这与impoly
无关.
Do you mean after calling impoly, you go into the figure window and select "Generate Code"? Which will create a function createfigure
- but this has nothing to do with impoly
.
有两种方法可以提取投资回报率.
在用impoly
选择区域之后,在关闭图形之前:
There are a couple of ways you can extract the ROI.
After choosing the area with impoly
, before closing the figure:
BW = createMask(h);
或者您可以使用getPosition
提取位置,然后使用roipoly
.
Or you can extract the position with getPosition
and then use roipoly
.
这篇关于通过蒙版在图像上应用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!