[Date Index]
[Thread Index]
[Author Index]
Q: Help processing large arrays?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg2563] Q: Help processing large arrays?
*From*: robert fuentes <robert at mps.lfwc.lockheed.com>
*Date*: Mon, 20 Nov 1995 01:50:21 -0500
*Organization*: Lockheed Martin Tactical Aircraft Systems
I'm doing several things in the area of image processing. Generally, I
have rather large arrays (e.g., 256 by 256 and larger) that I need to
apply some type of operation on. My programming technique is not very
mature and I am seeking suggestions. Here is a typical example of my
approach. In this case, I have a 381 by 289 image that I need to run a
Sobel operator over (i.e., convolve with a 3 by 3 Sobel operator). This
involves taking a 3 by 3 array and moving it over the image pixel by
pixel, applying the multipliers of the Sobel operator to the
corresponding 3 by 3 area of the image and replacing the value of the
image with the sum of the operation. Here is my code that I use, it seems
to be very slow (680+ seconds on a P90 with 32Mb ram):
where
image is the input image
rows is the number of rows in the image
cols is the number of columns in the image
kernel is the 3 by 3 Sobel operator
ki & kj are the dimensions of the kernel
basically, I calculate an adjustment for the edges around the image where
the operator will extend beyond the image boundaries, then for each pixel
in the image I construct a 3 by 3 array and multiply it by the input
kernel and then sum these up and replace the point in the image with the
result...
BeginPackage["`RoadProc`"]
Begin["`Private`"]
RPConvolve[image_,rows_,cols_,kernel_,ki_,kj_] :=
Module[
{iadjust,jadjust,mistart,mistop,mjstart,mjstop,
divider,nuimage,i,j,maskarea,istart,jstart,m,n},
iadjust = (ki-1)/2;
jadjust = (kj-1)/2;
mistart = iadjust+1;
mistop = rows - iadjust;
mjstart=jadjust+1;
mjstop = cols - jadjust;
nuimage = image;
For[i=mistart,i<=mistop,i++,
For[j=mjstart,j<=mjstop,j++,
maskarea = Table[image[[m,n]],
{m,i-iadjust,i+iadjust},
{n,j-jadjust,j+jadjust}];
nuimage[[i,j]] = Apply[Plus,Flatten[maskarea*kernel]];
];
];
nuimage
]
thanks for any help,
Robert Fuentes
robert at mps.lfwc.lockheed.com
Prev by Date:
**Bug: too subtle for me**
Next by Date:
**large linear systems**
Previous by thread:
**Bug: too subtle for me**
Next by thread:
**Re: Q: Help processing large arrays?**
| |