blockproc applied to ROI images

1 visualización (últimos 30 días)
Adrian Herrera
Adrian Herrera el 14 de Oct. de 2019
Respondida: Rik el 14 de Oct. de 2019
It is possible to get the global possition (while applying the filter) of a block while using the blockproc funtion?
Im = Frames(:,:,t);
M = imcomplement(Mask(:,:,t));
fun = @(block_struct) PeakFinder(block_struct.data);
B = blockproc(Im,[200 200],fun);
Here Im is my original image and M is the mask (ROI), Peak finder is the following function:
function F = PeakFinder (Im)
g = evalin('base','M');
f = @ SubPeakFinder;
F = roifilt2(Im,g,f);
end
I want to apply the filter "SubPeakFinder" to Im only in the ROI, but right now (above code) g loads the entire global ROI, and I haven't figured it out a way to select the part that corresponds to the block that it is being applied.
Thanks,

Respuesta aceptada

Rik
Rik el 14 de Oct. de 2019
Using a nested function will allow you to share variables without having to resort to evalin. As for your actual problem: you could switch to cellfun, or set the values that are false in your ROI to NaN and adapt your function accordingly. Another option is to use nested functions to share variables, and use an index array.
function B=foo
IM=rand(200,200);
Mask=rand(size(IM))<0.2;
indexArray=reshape(1:numel(IM),size(IM));
fun = @(block_struct) bar(block_struct.data);
B = blockproc(indexArray,[20 20],fun);
function out=bar(ind)
partIM=IM(ind);
partMask=Mask(ind);
%do something
out=max(partIM(partMask));
end
end

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by