Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
blockproc takes much longer than blkproc

Subject: blockproc takes much longer than blkproc

From: Chris

Date: 4 Aug, 2010 14:10:23

Message: 1 of 5

I want to downsample a binary image "I" such that no 1s are "lost" in the downsampling. I originally used blkproc like so:

ds_KeepWhite = @(x) max(x(:));
... calculate "blk_size" ...
I_ds = blkproc(I,[blk_size blk_size],ds_KeepWhite);

This worked and would take about 20 seconds ("I" is a large image). I then tried using blockproc because of the warning that blkproc will become obsolete:

ds_KeepWhite = @(block_struct) max(block_struct.data(:));
... calculate "blk_size" ...
I_ds = blockproc(I,[blk_size blk_size],ds_KeepWhite);

and the calculated time to perform the operation was 25 minutes! (I didn't change any of the other code besides the function definition and the call to the block processing algorithm).

Have I done something wrong? Or is this a bug? Thanks for any help you can give.
(Running v 7.9.0.529 R2009b, win64 system)

- Chris

Subject: blockproc takes much longer than blkproc

From: Sean

Date: 4 Aug, 2010 14:35:04

Message: 2 of 5

"Chris " <chris.peressotti@sunnybrook.ca> wrote in message <i3bscf$9ss$1@fred.mathworks.com>...
> I want to downsample a binary image "I" such that no 1s are "lost" in the downsampling. I originally used blkproc like so:
>
> ds_KeepWhite = @(x) max(x(:));
> ... calculate "blk_size" ...
> I_ds = blkproc(I,[blk_size blk_size],ds_KeepWhite);
>
> This worked and would take about 20 seconds ("I" is a large image). I then tried using blockproc because of the warning that blkproc will become obsolete:
>
> ds_KeepWhite = @(block_struct) max(block_struct.data(:));
> ... calculate "blk_size" ...
> I_ds = blockproc(I,[blk_size blk_size],ds_KeepWhite);
>
> and the calculated time to perform the operation was 25 minutes! (I didn't change any of the other code besides the function definition and the call to the block processing algorithm).
>
> Have I done something wrong? Or is this a bug? Thanks for any help you can give.
> (Running v 7.9.0.529 R2009b, win64 system)
>
> - Chris

This doesn't address your blkproc question but here's a way that might be faster:
%%%
%Make Test Image
I = rand(10)>.5;
I(:,[3 7]) = 0;%Set the 3rd and 7th col = 0
I([3 7],:) = 0;%Set the 3rd and 7th row = 0

%Engine
[r c] = find(I); %rows and cols with a 1
I2 = I(unique(r),:); %keep rows with a 1
I2(:,setxor(c,1:size(I,2))) = []; %get rid of cols without a 1

Subject: blockproc takes much longer than blkproc

From: Walter Roberson

Date: 4 Aug, 2010 16:00:41

Message: 3 of 5

Without looking at the actual operations you are doing:

There were some postings towards the beginning of the year in which
people found that blockproc is indeed *much* slower than blkproc .

I do not recall at the moment if there were any work-arounds, but
plausibly someone might have created a FEX contribution that sped up the
operation.

Subject: blockproc takes much longer than blkproc

From: Ashish Uthama

Date: 5 Aug, 2010 12:02:32

Message: 4 of 5

Walter Roberson wrote:
> There were some postings towards the beginning of the year in which
> people found that blockproc is indeed *much* slower than blkproc .

http://www.mathworks.com/matlabcentral/newsreader/view_thread/282819#757314

Subject: blockproc takes much longer than blkproc

From: Walter Roberson

Date: 5 Aug, 2010 14:20:57

Message: 5 of 5

Ashish Uthama wrote:
> Walter Roberson wrote:
>> There were some postings towards the beginning of the year in which
>> people found that blockproc is indeed *much* slower than blkproc .
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/282819#757314

Thanks for finding that; that was the thread I was thinking of.

Tags for this Thread

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.

Contact us