Is there any correlation kernel that keeps the roi of an image while removes the remained pixels?
2 次查看(过去 30 天)
显示 更早的评论
hi, I have already defined the roi of an image (I) by using roicolor, now I need to keep the pixels of I which are within roi and throw out the remaining pixels (the dimensions of output image should be equal to the dimensions of the roi array). I used roifilt2 but I do not know what correlation kernel (h) can be used for my purpose...
thanks
0 个评论
回答(1 个)
DGM
2023-5-1
Can you specify a particular filter kernel such that roifilt2() will preserve the area selected by the mask and discard the region outside? No.
Can you contrive a means to misuse roifilt2() for this task? Yes.
Consider the two images:
% a single-channel image
inpict = imread('cameraman.tif');
% a logical mask
mask = imread('sources/standardmods/cman/cmantifmk.png')>128;
% invert the mask and use a zero-valued kernel
%outpict = roifilt2(0,inpict,~mask);
% invert the mask and use a function handle which returns a
% zero-valued array of the same size and class as the image
outpict = roifilt2(inpict,~mask,@(x) 0*x);
Of course, both of these examples will fail for int16 images.
Should you use roifilt2() to do this job? No.
IPT roifilt2() is a tool to apply a function to an image segment and then composite the filtered segment back into the original image with the ostensible goal of reducing the amount of data that needs to be filtered. It combines a filtering process and a compositing process, and in this case, the filtering process is entirely unnecssary. To use roifilt2() for compositing alone would not only be wasteful and cryptic, it would impose unnecessary restrictions on what you could do.
If you want to do a basic compositng task like filling a masked region with a solid color, just do that.
% presuming the following:
% mask is logical-class
% image is not signed-integer class
% mask and image have same number of channels
outpict = inpict;
outpict(~mask) = 0;
This example requires about 13% as much time as misusing roifilt().
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!