in "fun" have access to the center values of the "colfilt" kernels?
3 ビュー (過去 30 日間)
古いコメントを表示
Would anybody know, how I can in "fun" have access to the center values of the "colfilt" kernels?
The kernels of the "colfilt" function are the columns in the array passed to "fun" by the "colfilt" function, and if for the m x n kernel the values for m and n have been odd numbers, then the value of the center pixel can be determined easily. But I did not find how to determine the values of the center pixels of the kernels of the colfilt function, if even numbers have been used to span the kernel.
I know that using the "nlfilter" function I can easily receive in "fun" the value of the center pixel from the kernel matrix passed to "fun" (according to the documentation it is to be found by "floor(([m n]+1)/2)" ). But, as a kernel of the "colfilt" function is not received in "fun" as an array, but as a column, I here did not find a valid formula to determine the position of the kernel´s center pixel, from which I could read out the value, as soon as an even m x n kernel dimension comes in.
Any idea how to always get the kernel´s center pixel´s value also from the "colfilt" function, also if an even dimension defining the kernel size has been used?
0 件のコメント
採用された回答
Anand
2014 年 4 月 2 日
You're going to have to store the linear index of where you expect the pixel to be and access that element of the array passed into fun. Here's an example showing how to replace each 5x5 block with the center pixel in that block.
I = imread('tire.tif');
blk = [5 5];
% Find linear index of center pixel
center = floor((blk+1)/2);
centerind = sub2ind(blk,center(1),center(2));
% Define anonymous function that replaces the 5x5 block with the center pixel.
% The center pixel is accessed as x(centerind), in this case, x(13). repmat
% is used to create a 5x5 block of this.
fun = @(x)repmat(x(centerind),size(x,1),size(x,2));
out = colfilt(I,blk,'distinct',fun);
You can just as easily replace 5x5 with another block size (odd or even).
Hope this helps.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!