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:
Convolving a matrix with a stack of images

Subject: Convolving a matrix with a stack of images

From: Bluebird

Date: 26 Aug, 2010 12:40:23

Message: 1 of 2

Hello,

I have a stack of images where each image is of size 20x20. The stack has 30,000 images. I want to convolve each of these images with matrix
sx=[ 1 0 -1
       2 0 -2
       1 0 -1] ( i.e. sobel operator)

The way that i am doing it is as the follwoing :

StackImagesX=zeros(20,20,size(30,000,3)); % To allocate the space
% looping over all images in one by way and do conv2 with the matrix
for i=1:size(StackImages,3)
StackImageX(:,:,i)=conv2(double(StackImages(:,:,i)),double(sx),'same');
end

Where StackImages are the 20x20x30,000 original images.

Doing this is time consuming, is there a way of avoiding this for loop?

Regards

Subject: Convolving a matrix with a stack of images

From: kinor

Date: 26 Aug, 2010 15:08:05

Message: 2 of 2

"Bluebird " <wlouis@ryerson.ca> wrote in message <i55nbn$aeo$1@fred.mathworks.com>...
> Hello,
>
> I have a stack of images where each image is of size 20x20. The stack has 30,000 images. I want to convolve each of these images with matrix
> sx=[ 1 0 -1
> 2 0 -2
> 1 0 -1] ( i.e. sobel operator)
>
> The way that i am doing it is as the follwoing :
>
> StackImagesX=zeros(20,20,size(30,000,3)); % To allocate the space
> % looping over all images in one by way and do conv2 with the matrix
> for i=1:size(StackImages,3)
> StackImageX(:,:,i)=conv2(double(StackImages(:,:,i)),double(sx),'same');
> end
>
> Where StackImages are the 20x20x30,000 original images.
>
> Doing this is time consuming, is there a way of avoiding this for loop?
>
> Regards

Hi,

if you have access to the image processing toolbox just use imfilter

hth
kinor

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