From: Chris on
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
From: Sean on
"Chris " <chris.peressotti(a)sunnybrook.ca> wrote in message <i3bscf$9ss$1(a)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
From: Walter Roberson on
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.
From: Ashish Uthama on
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
From: Walter Roberson on
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.