将算法应用于图像的特定区域 [英] Applying an algorithm to a specific region of an image

查看:70
本文介绍了将算法应用于图像的特定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅将算法应用于图像的特定区域.我尝试了imfreehand,但是至少对于我来说,无法使用此功能来做到这一点.

I'm trying to apply an algorithm only to a specific region of an image. I tried imfreehand, but not able, at least for me, to do that using this function.

那么,运行我的代码时是否有某种方法可以将操作仅应用于MATLAB中图像的某些特定区域?

So, is there some way when running my code for the operations to be applied only to some specific region of an image in MATLAB?

谢谢.

推荐答案

使用由任何"imroi"函数定义的遮罩-包括imfreehand和imellipse,您可以使用roifilt2使用给定的过滤器或函数仅过滤roi

Using a mask defined by any of the "imroi" functions - imfreehand and imellipse included, you can use roifilt2 to filter just the roi using a given filter or function.

首先,定义区域:

imshow(I); %display your image
h = imfreehand; % now pick the region
BW = createmask(h); %makes BW mask

然后,通过以下方式之一使用roifilt2-

Then, use roifilt2 in one of the following ways -

定义一个过滤器并应用它:

Define a filter and apply it:

H = fspecial('unsharp');
I2 = roifilt2(H,I,BW);`

将给定函数应用于roi:

Apply a given function to the roi:

I2 = roifilt2(I, BW, 'histeq');

将给定函数应用于roi,并指定参数:

Apply a given function to the roi, specifying parameters:

fh = @(I)(histeq(I,5)); %define function
I2 = roifilt2(I, BW, fh); 

最后一个等价于调用I2 = hist(I,5);但仅适用于已定义的投资回报率.

The last is equivalent to calling I2 = hist(I,5); but only works on the defined roi.

ETA:

如果要在roi上调用多个函数,定义您自己的函数可能是最简单的,该函数接受图像输入(以及可选的其他参数),将适当的滤镜/函数应用于图像,然后输出最终图像-然后您将以与上述"histeq"相同的方式调用"myfunc".

If you want to call multiple functions on the roi, it may be easiest to define your own function, which takes an image input (and optionally, other parameters), applies the appropriate filters/functions to the image, and outputs a final image - you would then call "myfunc" in the same way as "histeq" above.

这篇关于将算法应用于图像的特定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆