Usage of Blkproc function in matlab

6 visualizaciones (últimos 30 días)
SaiGeetha Selvam
SaiGeetha Selvam el 11 de Nov. de 2011
Hi all
My objective is that a binary image is divided into 7×7 equal blocks. We scan each of the resulting 49 blocks along both horizontal and vertical directions. In each such scan, we count the number of transitions (white to black and vice-versa).Thus, we obtain a 2 × 49 = 98 component transition feature vector corresponding to each character sample.
my function file f.m is as follows
function f
global countof021;
global countof120;
countof021=0;
countof120=0;
for i = 1:3
for j= 1:4
if ( (img(i,j)==1) && (img((i+1),j)==0) )
countof120=countof120+1;
elseif ( (img(i,j)==0) && (img((i+1),j)==0) )
countof021=countof021+1;
end
end
end
end
My count of the 0 to 1 or 1 to 0 transition file is count120.m is as follows
clc;
close all;
clear all;
im1 =imread('D:\SAIGEETHA\ME\V SEMESTER\MINI PROJECT\000t01.tif');
[m,n]=size(im1);
resizedimage=imresize(im1,[343 343]);
img=resizedimage;
countof021=0;
countof120=0;
blockofimage=zeros(49);
dividedimage = blkproc(img,[7 7],@(x)f);
disp('img=');
disp(img);
disp('countof120=');
disp(countof120);
disp('countof021=');
disp(countof021);
The error message is
??? Error using ==> f
Too many output arguments.
Error in ==> @(x)f
Error in ==> blkproc at 100
firstBlock = feval(fun,x,params{:});
Error in ==> count120 at 11
dividedimage = blkproc(img,[7 7],@(x)f);
Please help me to accomplish this .
Thanks
Saigeetha

Respuestas (2)

Walter Roberson
Walter Roberson el 11 de Nov. de 2011
The function you pass in to blkproc() must have an output argument. If you are not going to use the matrix blkproc() creates from the outputs of f, then return something like 0 and ignore the result afterwards.
There is no point in using blkproc() with that f, since that f ignores its inputs and the current location within the block and always calculates the same thing -- and always overwrites the global variables with the exact same calculated values. Besides, that f is going to crash because it attempts to access the variable "img" which is not defined within the scope of f.
Oh yes: variables are only global within routines that specifically declare them as global, so in your count120.m the variables countof021 and countof120 are going to be the local variables initialized to 0 earlier in count120.m
Remember, blkproc() is going to be run on all of the blocks before control is returned to any routine that might read out the global variables.
  1 comentario
Kaustubha Govind
Kaustubha Govind el 11 de Nov. de 2011
+1
I totally overlooked the application!

Iniciar sesión para comentar.


Kaustubha Govind
Kaustubha Govind el 11 de Nov. de 2011
Try using it as blkproc(img,[7 7],@()f); and see if the error goes away. Since "f" does not have any output arguments, you don't need to specify the "x" in the parentheses.

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by