Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: A time consuming function
Replies: 2   Last Post: Mar 29, 2012 8:21 AM

 Messages: [ Previous | Next ]
 draasoft Posts: 12 Registered: 3/28/12
A time consuming function
Posted: Mar 28, 2012 12:48 PM

Hi everyone,

Could any one tell me how to make this function faster (it gets as inputs an image + 4 parameters)? I tried to vectorize it as shown below, but an error occurs given just after the second code).

Many thanks

% The original code

function [out]=enhance2(in,a,b,c,k)
[aa bb]=size(in);

dev=stdfilt(in);
M=mean2(in);
H = fspecial('average',[3 3]);
moy = double(imfilter(in, H));

for j=1:bb
for i=1:aa
out(i,j)=(k*M/(dev(i,j)+b))*(in(i,j)-c*moy(i,j))+moy(i,j)^a;
end
end
return

% Code 2:
function [out]=enhance2(in,a,b,c,k)

[aa bb]=size(in);
dev=stdfilt(in);
M=mean2(in);
H = fspecial('average',[3 3]);
moy = double(imfilter(in, H));

out=(k*M./(dev+b)).*(in-c.*moy)+moy.^a;

return

error: Integers can only be combined with integers of the
same class, or scalar doubles.

Date Subject Author
3/28/12 draasoft
3/29/12 draasoft
3/29/12 draasoft