Clear Filters
Clear Filters

I want to prepare a code for fuzzy rule based Edge detection. I have a problem with ' colfilt' command.

1 view (last 30 days)
after running the code,I reached to the following error :
??? Error using ==> reshape To RESHAPE the number of elements must not change.
Error in ==> colfilt at 149 b = reshape(feval(fun,x,params{:}), size(a));
Error in ==> test2 at 89 x1=uint8(colfilt(x1,[2,2],'sliding',@fedge1)) I defined the function fedge as follows: function [ uu ] = fedge1( P11,P21,P31,P41 )
kk=readfis('fis.fis') t=kk.input
P11=double(t(1).name) P21=double(t(2).name) P31=double(t(3).name) P41=double(t(4).name) P=[P11;P21;P31;P41] uu=evalfis(P(:,2),kk)
end I guess that I have some problem in correct defining of function handle for the command ' colfilt '. How can I solve this problem?

Answers (1)

Blackadder
Blackadder on 9 Oct 2016
Edited: Blackadder on 9 Oct 2016
This response probably comes a bit late but I only just discovered the solution myself. Maybe my answer still helps you or anyone with a similar problem.
The colfilt() function has an optimization built in that is only briefly mentioned in the documentation. The documentation states: "To save memory, the colfilt function might divide A into subimages and process one subimage at a time. This implies that fun may be called multiple times, and that the first argument to fun may have a different number of columns each time."
This means that colfilt() may execute in two entirely different ways.
  1. Option: The input matrix is small enough to be filtered in a single step. colfilt() then passes the whole reshaped input matrix to the filter function.
  2. Option: The input matrix is too large to be reshaped without ludacris memory consumption. colfilt() then traverses the input matrix in chunks.
To determine which of the two options to take, colfilt() internally calls the bestblk() function. The error you are getting is typical for situations in which bestblk() decides in favor of option 2.
If bestblk() signals that the input matrix is too large, colfilt() will proceed in three steps. Assuming that your kernel has k pixels, these steps are:
  1. Step: colfilt() will call the filter function once with a k x 1 column matrix to determine the data type returned from the filter function.
  2. Step: colfilt() will then call the filter function multiple times with a k x m input matrix. The number of colums m stems from the call to bestblk().
  3. Step: finally, colfilt() will recombine the outputs from the multiple calls to the filter function into one filtered image. This filtered image is exactly identical to the result that option 1 would have yielded.
Most likely, your filter function "fedge1" expects a matrix which derives directly from your image size. This causes an error whenever the image is too large and colfilt() executes step 1 as described above.
Solution: You must set up "fedge1" such that it can deal with arbitrary input matrices of size k x m.

Community Treasure Hunt

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

Start Hunting!