Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:26:15+00:00 2026-06-06T21:26:15+00:00

I’m trying to calculate a 3d sobel filter in python. I have a pretty

  • 0

I’m trying to calculate a 3d sobel filter in python. I have a pretty good code for 2d image which is below.

btw. my original image is uint8 type.

    preSobel = preSobel.astype('int32')
    dx = ndimage.sobel(preSobel, 0)  # horizontal derivative
    dy = ndimage.sobel(preSobel, 1)  # vertical derivative
    mag = numpy.hypot(dx, dy)  # magnitude
    mag *= 255.0 / numpy.max(mag)  # normalize (Q&D)
    img[i,:,:]=mag

but from my understanding of the wiki page for calculating 2d, i should have multiplied the 1d sobel results rather than hypot :confused

anyway, to go to 3d, I guess I need to calculate 1d sobel on each axis and then multiply all but I’m not sure… Is there any library out there that calculates 3d sobel faster ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:26:17+00:00Added an answer on June 6, 2026 at 9:26 pm

    First, in reference to your wikipedia link: The multiplication there is referring to the way to construct the sobel convolution kernel, not the end result.

    For a 2D sobel filter you need a kernel to get the derivate in x direction, and another kernel to get the derivate in Y direction, e.g.
    enter image description here

    This is essentially what your two commands do, so if you are using numpy you do not need to construct these kernels yourself.

    dx = ndimage.sobel(preSobel, 0)  # horizontal derivative
    dy = ndimage.sobel(preSobel, 1)  # vertical derivative
    

    Now for the 3D case you need 3 operations with 3 kernels, one for dx, dy, dz.
    The linked wiki section is telling you how to construct the kernels by multiplying components. The finished sobel kernel for dZ for example is a 3x3x3 matrix that looks like this:

    enter image description here

    To get the magnitude you still have to take the square root of the squared derivatives (the hypotenuse) afterwards.

    I do not have numpy but as far as I can tell from the documentation the ndimage sobel command can deal with any number of dimensions, so again, the kernels are already provided:

    dx = ndimage.sobel(your3Dmatrix, 0)  # x derivative
    dy = ndimage.sobel(your3Dmatrix, 1)  # y derivative
    dz = ndimage.sobel(your3Dmatrix, 2)  # z derivative
    

    now the hypotenuse command probably only take 2 parameters, so you will have to find another way to efficiently calculate mag = sqrt(dxdx + dydy + dz*dz) .
    But NumPy should have everything you need for that.


    Update

    Actually, if you are only interested in the magnitude anyway, there is a complete function in numpy for this:

     mag = generic_gradient_magnitude(your3Dmatrix, sobel)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
I have two tables with like below codes: Table: Accounts id | username |
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.