I've have functions in Matlab that takes two arguments, an image and a kernel and does various image processing applications on it. The signature is Gen_Filt(kernel,img) for various filtering operations. I'm trying to create a second function that closes over the filterings operation with a specific kernel so it can do a particular operation with images.
function [closure] =Close_Over(General,kernel)
function[out_img]=inner(img)
out_img=General(kernel,img);
end
closure=@inner;
end
So this will take a specific type of filtering operation (Gen_Filt signature) and a specific kernel and return a function handler with the kernel bound to that specific filtering operation. However, it seems to call the filtering operation function and gives the following error:
Error in Gen_Filt (line 61)
out_img=conv2(img,kernel,'same');
which makes me think it's trying to evaluate the filtering operation Gen_Filt before I can call the handler with a specific image argument.
Do I understand the problem correctly and/or am I making a mistake?
Gen_Filt? Your code snipped doesn’t even reference it! And what is the actual error message? Please read minimal reproducible example, then edit your question accordingly. It’s hard to understand exactly what you did and where the error is generated with the information you’ve given. - Cris LuengoClose_Over(Gen_Filt,my_kernel), in which case you are trying to callGen_Filt. In MATLAB, writingGen_Filtis the same as writingGen_Filt(). You would need to callClose_Over(@Gen_Filt,my_kernel). Please edit your question to include a minimal reproducible example, then we can see what the actual problem was. - Cris Luengomy_filter = @(img)Gen_Filt(kernel,img), withkernelknown in the current workspace. Then,my_filter(some_image)will apply theGen_Filtfunction withkernelas it existed when you created the closure (which is called anonymous function in MATLAB). - Cris Luengo