Python Forum
Numpy or Scipy Variance Convolution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numpy or Scipy Variance Convolution
#1
I was wondering what the most efficient / fastest way to code a Variance Convolution would be in Python?

I currently have the following code, that takes a 3D Numpy array, creates a maximum pixelwise intensity layer, and finds the convolved variance of that image using OpenCV.  This seems to be far too slow, and from what I can see, GPU support for OpenCV-Python isn't in place yet.

Any suggestions for a faster approach would be much appreciated.

MaxFrom3DArray = numpy.amax(imgArray, axis=0)  # imgArray is 3D numpy array
Back2ImMax = Image.fromarray(MaxFrom3DArray, 'P')
Back2ImMax.save(os.path.join(MaxFromMulti, filename), "TIFF")

ForVariance = cv2.imread((MaxFromMulti + filename), cv2.IMREAD_UNCHANGED)
wlen = 40
def winVar(img, wlen):
wmean, wsqrmean = (cv2.boxFilter(x, -1, (wlen, wlen),
  borderType=cv2.BORDER_REFLECT) for x in (img, img*img))
return wsqrmean - wmean*wmean
windowVar = winVar(ForVariance, wlen)
numpy.set_printoptions(threshold='nan')
print windowVar

Best wishes

TWP
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 527 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Python for Analysis of variance / Anova xxxlabradorxxx 1 780 Sep-25-2023, 07:11 PM
Last Post: jefsummers
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,594 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Convolution "same" in Python doesn't work as Matlab claw91 4 3,736 Oct-01-2020, 08:59 AM
Last Post: claw91
  Cant's get accurate unbiased variance. Alex009988 1 2,277 Aug-13-2019, 02:55 PM
Last Post: ichabod801
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,966 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  Convolution with numpy Tina 3 10,825 Mar-07-2017, 03:16 PM
Last Post: Tina

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020