Thread Subject: Error using blkproc function

Subject: Error using blkproc function

From: fit institute

Date: 6 Mar, 2011 15:58:20

Message: 1 of 9

t=dctmtx(100)
im2double(I);
 fun = @(block_struct) (block_struct.data)*(t)
        I2 = blockproc(I,[100 100],fun);
        figure;
        imshow(I);
        figure;
        imshow(I2);


when using the above code to compute DCT on an image matrix( I),i'm getting the following error



??? Error using ==> blockproc>userfunDispatcher at 719
There was an error when evaluating the user supplied
function FUN. The error message was:

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

Error in ==> blockproc at 214
output_block =
userfunDispatcher(fun,input_struct,trim_border);


please help me fix this
myemail: bibin.paul.c@gmail.com

Subject: Error using blkproc function

From: Think blue, count two.

Date: 6 Mar, 2011 17:05:19

Message: 2 of 9

On 06/03/11 9:58 AM, fit institute wrote:
> t=dctmtx(100)
> im2double(I);
> fun = @(block_struct) (block_struct.data)*(t)
> I2 = blockproc(I,[100 100],fun);
> figure;
> imshow(I);
> figure;
> imshow(I2);
>
>
> when using the above code to compute DCT on an image matrix( I),i'm
> getting the following error
>
>
>
> ??? Error using ==> blockproc>userfunDispatcher at 719
> There was an error when evaluating the user supplied
> function FUN. The error message was:
>
> Integers can only be combined with integers of the same
> class, or scalar doubles.

Your fun is attempting to do a matrix multiply (in the mathematical
sense) between the double precision numbers that result from dctmtx()
and the integer-class numbers that are block_struct.data . Mixing
integral numbers and double precision is not generally supported in
Matlab except when the only double precision number is a scalar.

So, define:

fun = @(block_struct) double(block_struct.data)*(t)

Please double-check, though, whether you want to do a matrix
multiplication in the mathematical sense, or an element-by-element
multiplication. Element-by-element multiplication of corresponding
matrix entries requires the .* operator instead of the * operator.

Subject: Error using blkproc function

From: Bruno Luong

Date: 6 Mar, 2011 17:26:22

Message: 3 of 9

> im2double(I);

Why calling a function without assigning the result???

You probably need to read the Matlab "Getting Started" guide.

Bruno

Subject: Error using blkproc function

From: fit institute

Date: 7 Mar, 2011 14:34:23

Message: 4 of 9

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <il0g3u$mcg$1@fred.mathworks.com>...
> > im2double(I);
>
> Why calling a function without assigning the result???
>
> You probably need to read the Matlab "Getting Started" guide.
>
> Bruno


thanks a lot bruno....but still i'm getting error


The modified code is
...................................................................
  t=dctmtx(100)
        t1=im2double(t)
        I = imread('moon.tif')
        I1=im2double(I)
        fun = @(block_struct) (block_struct.data)*(t1);
        
        I2 = blockproc(I1,[100 100],fun);
.............................................................................

and the error i'm getting is

??? Error using ==> blockproc>userfunDispatcher at 719
There was an error when evaluating the user supplied function FUN. The error message was:

Inner matrix dimensions must agree.

Error in ==> blockproc>getOutputContainer at 539
        last_col_output = userfunDispatcher(fun,input_struct,trim_border);

Error in ==> blockproc at 238
[b,rows_probed,cols_probed] = getOutputContainer(a,asize,b,fun,block,...

Error in ==> Untitled at 7
        I2 = blockproc(I1,[100 100],fun);
 
        

Subject: Error using blkproc function

From: fit institute

Date: 7 Mar, 2011 14:47:24

Message: 5 of 9

"Think blue, count two." <roberson@hushmail.com> wrote in message <k9Pcp.72167$QD2.17166@newsfe10.iad>...
> On 06/03/11 9:58 AM, fit institute wrote:
> > t=dctmtx(100)
> > im2double(I);
> > fun = @(block_struct) (block_struct.data)*(t)
> > I2 = blockproc(I,[100 100],fun);
> > figure;
> > imshow(I);
> > figure;
> > imshow(I2);
> >
> >
> > when using the above code to compute DCT on an image matrix( I),i'm
> > getting the following error
> >
> >
> >
> > ??? Error using ==> blockproc>userfunDispatcher at 719
> > There was an error when evaluating the user supplied
> > function FUN. The error message was:
> >
> > Integers can only be combined with integers of the same
> > class, or scalar doubles.
>
> Your fun is attempting to do a matrix multiply (in the mathematical
> sense) between the double precision numbers that result from dctmtx()
> and the integer-class numbers that are block_struct.data . Mixing
> integral numbers and double precision is not generally supported in
> Matlab except when the only double precision number is a scalar.
>
> So, define:
>
> fun = @(block_struct) double(block_struct.data)*(t)
>
> Please double-check, though, whether you want to do a matrix
> multiplication in the mathematical sense, or an element-by-element
> multiplication. Element-by-element multiplication of corresponding
> matrix entries requires the .* operator instead of the * operator.



thanks think blue,count two

i had made the modification u hav mentioned
  (>>fun = @(block_struct) double(block_struct.data)*(t)....................but still getting an error

??? Error using ==> blockproc>userfunDispatcher at 719
There was an error when evaluating the user supplied function FUN. The error message was:

Inner matrix dimensions must agree.

Error in ==> blockproc>getOutputContainer at 539
        last_col_output = userfunDispatcher(fun,input_struct,trim_border);

Error in ==> blockproc at 238
[b,rows_probed,cols_probed] = getOutputContainer(a,asize,b,fun,block,...

Error in ==> Untitled2 at 4
I2 = blockproc(I,[100 100],fun);

Subject: Error using blkproc function

From: Bruno Luong

Date: 7 Mar, 2011 14:53:05

Message: 6 of 9

"fit institute " <bibin.paul.c@gmail.com> wrote in message <il2r5s$7hv$1@fred.mathworks.com>...
Please reread the suggestion from "Think blue, count two":

> ... Element-by-element multiplication of corresponding
> matrix entries requires the .* operator instead of the * operator.

Bruno

Subject: Error using blkproc function

From: fit institute

Date: 7 Mar, 2011 15:29:49

Message: 7 of 9

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <il2rgh$hsl$1@fred.mathworks.com>...
> "fit institute " <bibin.paul.c@gmail.com> wrote in message <il2r5s$7hv$1@fred.mathworks.com>...
> Please reread the suggestion from "Think blue, count two":
>
> > ... Element-by-element multiplication of corresponding
> > matrix entries requires the .* operator instead of the * operator.
>
> Bruno


 hi bruno,

 i'm not looking for element by element multiplication ........but i want the image to be broken into blocks of 100*100 pixels ...and do a multiplicatiion of each such blocks with dctmtx which contain 100*100 elements


thanks you in advance....................

Subject: Error using blkproc function

From: Brendan Hannigan

Date: 7 Mar, 2011 20:13:21

Message: 8 of 9

"fit institute " <bibin.paul.c@gmail.com> wrote in message <il2tld$o9c$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <il2rgh$hsl$1@fred.mathworks.com>...
> > "fit institute " <bibin.paul.c@gmail.com> wrote in message <il2r5s$7hv$1@fred.mathworks.com>...
> > Please reread the suggestion from "Think blue, count two":
> >
> > > ... Element-by-element multiplication of corresponding
> > > matrix entries requires the .* operator instead of the * operator.
> >
> > Bruno
>
>
> hi bruno,
>
> i'm not looking for element by element multiplication ........but i want the image to be broken into blocks of 100*100 pixels ...and do a multiplicatiion of each such blocks with dctmtx which contain 100*100 elements
>
>
> thanks you in advance....................

by default, BLOCKPROC does not pad partial blocks along the edges. Since the size of your input image, moon.tif, is [537 358] and you are dividing your image into blocks of size [100 100] using BLOCKPROC, you will have "partial blocks" along the right and bottom "edges" of the image since 537x358 is not evenly divisible by 100x100.

When BLOCKPROC attempts to process these "partial blocks", it will encounter this error since it will attempt to do a matrix multiply on a the 100x100 dctmtx matrix on a smaller partial-sized block.

BLOCKPROC offers a variety of ways to deal with padding issues. You can first specify the parameter 'PadPartialBlocks'. By default this is set to false, but if you set this parameter to true, BLOCKPROC will automatically pad your image such that all blocks processed are "full sized". This will fix the error you are seeing.

When this parameter is set to true, BLOCKPROC will use "zero-padding" by defualt, padding the extra space with zeros. If you want some other type of padding behavior you can additionally specify the 'PadMethod' parameter, which allows other styles of padding such as 'replicate', 'symmetric', or padding using other constant values.

hope this helps!
-brendan

Subject: Error using blkproc function

From: fit institute

Date: 8 Mar, 2011 15:26:19

Message: 9 of 9

"Brendan Hannigan" wrote in message <il3e91$kak$1@fred.mathworks.com>...
> "fit institute " <bibin.paul.c@gmail.com> wrote in message <il2tld$o9c$1@fred.mathworks.com>...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <il2rgh$hsl$1@fred.mathworks.com>...
> > > "fit institute " <bibin.paul.c@gmail.com> wrote in message <il2r5s$7hv$1@fred.mathworks.com>...
> > > Please reread the suggestion from "Think blue, count two":
> > >
> > > > ... Element-by-element multiplication of corresponding
> > > > matrix entries requires the .* operator instead of the * operator.
> > >
> > > Bruno
> >
> >
> > hi bruno,
> >
> > i'm not looking for element by element multiplication ........but i want the image to be broken into blocks of 100*100 pixels ...and do a multiplicatiion of each such blocks with dctmtx which contain 100*100 elements
> >

thanks a lot......... brendan........and that fixes my error ......special thanks for your good explanation...........

bibin
> >
> > thanks you in advance....................
>
> by default, BLOCKPROC does not pad partial blocks along the edges. Since the size of your input image, moon.tif, is [537 358] and you are dividing your image into blocks of size [100 100] using BLOCKPROC, you will have "partial blocks" along the right and bottom "edges" of the image since 537x358 is not evenly divisible by 100x100.
>
> When BLOCKPROC attempts to process these "partial blocks", it will encounter this error since it will attempt to do a matrix multiply on a the 100x100 dctmtx matrix on a smaller partial-sized block.
>
> BLOCKPROC offers a variety of ways to deal with padding issues. You can first specify the parameter 'PadPartialBlocks'. By default this is set to false, but if you set this parameter to true, BLOCKPROC will automatically pad your image such that all blocks processed are "full sized". This will fix the error you are seeing.
>
> When this parameter is set to true, BLOCKPROC will use "zero-padding" by defualt, padding the extra space with zeros. If you want some other type of padding behavior you can additionally specify the 'PadMethod' parameter, which allows other styles of padding such as 'replicate', 'symmetric', or padding using other constant values.
>
> hope this helps!
> -brendan

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
blockproc Brendan Hannigan 8 Mar, 2011 15:50:38
dct fit institute 6 Mar, 2011 10:59:05
rssFeed for this Thread

Contact us at files@mathworks.com