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:
blkproc as scanning window but without padding

Subject: blkproc as scanning window but without padding

From: Louis

Date: 1 Nov, 2010 15:07:03

Message: 1 of 5

Hello,
I am using the blkproc as a scanning window instead of my usual two for-loop procedure.

% scanning of 24x24 window with a 2 pixel shift
IndP=blkproc(Image,[2 2],[11 11],@(x) somefunction);

It does work fine but my issue is the follwoing:

It works similar to conv function with 'full' option such that it starts from the first pixel (1,1) and padds the required space with zeros. However, i want it to work as conv with 'same' option such that it starts from pixel (12,12) so the scanning window is actually starting from pixel (1,1) of the image.

You might suggest that i just crop out the first 11 rows and 11 columns but this will not work properly in my case since if you notice that pixel 12,12 will not scanned as blkproc will go such that 1,1 then 1,3 then 1,5 etc

I hope my explanation is adequate to understand my case.

I appreciate your suggestions

Louis

Subject: blkproc as scanning window but without padding

From: Sean

Date: 1 Nov, 2010 15:20:05

Message: 2 of 5

"Louis " <wlouis@ryerson.ca> wrote in message <iaml2n$jmn$1@fred.mathworks.com>...
> Hello,
> I am using the blkproc as a scanning window instead of my usual two for-loop procedure.
>
> % scanning of 24x24 window with a 2 pixel shift
> IndP=blkproc(Image,[2 2],[11 11],@(x) somefunction);
>
> It does work fine but my issue is the follwoing:
>
> It works similar to conv function with 'full' option such that it starts from the first pixel (1,1) and padds the required space with zeros. However, i want it to work as conv with 'same' option such that it starts from pixel (12,12) so the scanning window is actually starting from pixel (1,1) of the image.
>
> You might suggest that i just crop out the first 11 rows and 11 columns but this will not work properly in my case since if you notice that pixel 12,12 will not scanned as blkproc will go such that 1,1 then 1,3 then 1,5 etc
>
> I hope my explanation is adequate to understand my case.
>
> I appreciate your suggestions
>
> Louis

Why don't you run it the way it's being run right now and then only keep the values from in your center?

Something like:
map = true(size(Image));
map(12:end-11,12:end-11) = false;
IndP(map) = 0;% or Image(map) whatever it is you want.

Subject: blkproc as scanning window but without padding

From: Louis

Date: 1 Nov, 2010 15:45:06

Message: 3 of 5

Hello Sean,

Thank you for your response. I wish i can apply your suggestion but to the best of my knowledge of understanding blkproc it wont be able to do it.

The way that i understood blkproc, and also the way i used it, is that i have to apply the function (@(x) somefuntion) internally and the result on IndP is the final result. Hence, the block of my image that goes from (1:24,1:24) will never be examined, and I cannot interpret the result of block 1:24,1:24 from IndP of other examined blocks.


Thank you :)

Louis

Subject: blkproc as scanning window but without padding

From: Brendan Hannigan

Date: 1 Nov, 2010 18:01:04

Message: 4 of 5

"Louis " <wlouis@ryerson.ca> wrote in message <iamna2$hn0$1@fred.mathworks.com>...
> Hello Sean,
>
> Thank you for your response. I wish i can apply your suggestion but to the best of my knowledge of understanding blkproc it wont be able to do it.
>
> The way that i understood blkproc, and also the way i used it, is that i have to apply the function (@(x) somefuntion) internally and the result on IndP is the final result. Hence, the block of my image that goes from (1:24,1:24) will never be examined, and I cannot interpret the result of block 1:24,1:24 from IndP of other examined blocks.
>
>
> Thank you :)
>
> Louis

Hi Louis,

I'm not sure I understand exactly what you want and I'm curious about your use case where you want this behavior. Could you give us a bit of background or context to this problem, a description of the data and what you are trying to accomplish?

If I am understanding your request, you want your result to be generated by operating the only the (interior) portions of the image, such that your border padding reaches exactly to the edge of your "real" image data (and not beyond into the zero-padding).

If your problem is only the single pixel offset you are experiencing due to your odd-numbered border values, can you just pre-pad the image with an extra pixel and then crop it back off at the end? like this:

% im1 is your original image
im2 = padarray(im1, [1 1]);
im3 = blkproc(im2, [2 2], [11 11],@myfun);
im4 = im3(13:end-12,13:end-12);

thanks!
-brendan

Subject: blkproc as scanning window but without padding

From: Louis

Date: 1 Nov, 2010 18:39:03

Message: 5 of 5

Hello Brendan,

I work on object detection, so this is basically a scanning window (of size 24x24 and shift of 2 pixels in the x and y direction) that scans the image multiple sizes (the window size is fixed but the image is pyramid downsampled). Each window is treated separately such that it is passed to a classifier (which i named @(x) somefunction) to decide whether that window is the object i am looking for or not.

The way that i am working around this issue is same as the method you mentioned however some complications occur when the image is resized. The problem that i am facing is the difficulties of mapping the detection on the scaled image to its corresponding in the actual size :) sorry if i confused you more!

So if can make blkproc act as 'same' option then this issue won't occur and i will treat it as what i was doing using 2 x and y directions for-loops :)


Thank you

Louis

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