Filter löschen
Filter löschen

Problem with blockprocess while using the block data for feature extraction

1 Ansicht (letzte 30 Tage)
Hi,
I am using blockprocess for splitting the image into 10x10 overlapping image blocks and I want to extract features of these blocks but matlab is giving errors. The code for the task is pasted here.
The matlab error is
??? Error using ==> blockproc>userfunDispatcher at 719
There was an error when evaluating the user supplied function FUN. The error message was:
Invalid filename.
Error in ==> blockproc at 214
output_block = userfunDispatcher(fun,input_struct,trim_border);
Error in ==> Main at 57
B= blockproc(g,[4 4],fun);%,'BorderSize',[3 3]); %[M + 2*V, N + 2*H]
Code:
fun=@(block_struct)feature_extraction(block_struct.data);
B= blockproc(g,[4 4],fun,'BorderSize',[3 3]);
Feature extraction function code
function features=feature_extraction(name_images)
[num_im,q]=size(name_images);
features=zeros(num_im,12);
for i=1:num_im
A=imread(name_images(i,:));
A=double(A);
%Normalization of the pixels intensity in [0, N_gray-1]
A=round((N_gray-1)*((A-min(A(:)))/(max(A(:))-min(A(:)))));
features(i,1)=mean2(A);
features(i,2)=std2(A);
features(i,3)=skewness(A(:));
features(i,4)=kurtosis(A(:));
end
kindly guide me what's wrong with it and how may i fix it. is there any alternate way to do it

Akzeptierte Antwort

Image Analyst
Image Analyst am 22 Dez. 2013
You forgot to post the error! In the meantime, check out these two demos for how to use blockproc().
There is also a FAQ entry on non -overlapping blocks, http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F. If you want overlapping blocks, then if they overlap by all but one pixel as they slide along, then you should use nlfilter() instead of blockproc(). Overlaps of other amounts are not very common. Why do you want overlap?
  1 Kommentar
Arslan Ahmad
Arslan Ahmad am 22 Dez. 2013
I want overlaps because there is a possibility that in non overlapping windows the point of interest would be divided

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 22 Dez. 2013
You can't do this:
B=1 blockproc(g,[4 4],fun,'BorderSize',[3 3]);
You have a one, then a space, then a blockproc call. Why is the 1 and a space there????
  8 Kommentare
Image Analyst
Image Analyst am 22 Dez. 2013
This is the error message I got. I'm not sure why you didn't get all this. Maybe it's because you have an old version.
>> blockprocFunDispatcher
Undefined function or variable 'blockprocFunDispatcher'.
>> blockprocFunDispatcher
Undefined function or variable 'blockprocFunDispatcher'.
>> test3
Function BLOCKPROC encountered an error while evaluating the user supplied function handle, FUN.
The cause of the error was:
Error using imread>parse_inputs (line 457)
The filename or url argument must be a string.
Error in imread (line 316)
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
Error in test3>feature_extraction (line 13)
A=imread(name_images(i,:));
Error in test3>@(block_struct)feature_extraction(block_struct.data) (line 5)
fun=@(block_struct)feature_extraction(block_struct.data);
Error in blockprocFunDispatcher (line 13)
output_block = fun(block_struct);
Error in blockprocInMemory (line 80)
[ul_output fun_nargout] = blockprocFunDispatcher(fun,block_struct,...
Error in blockproc (line 236)
result_image = blockprocInMemory(source,fun,options);
Error in test3 (line 6)
B= blockproc(g,[4 4],fun,'BorderSize',[3 3]);
Basically the problem looks to be this line:
A=imread(name_images(i,:));
Now, name_images is not a string, but you're trying to treat it as one. I think it's a structure. Once you understand my demo you'll know how to handle the submimage input into your custom function. Why don't you set a breakpoint in the function and step through it to see what's going on? Using the debugger yourself is a lot faster than posting message here.
Arslan Ahmad
Arslan Ahmad am 22 Dez. 2013
@Image Analyst
Dear Sir,
I am very much grateful for your help. The error was with the function its working now.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by