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

  • Home
  • SEARCH
  • 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 6327105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:13:06+00:00 2026-05-24T17:13:06+00:00

I am using a numpy masked array to perform some image processing. The mask

  • 0

I am using a numpy masked array to perform some image processing. The mask is in place to handle NoData pixels which surround the image (a necessary border as these are map projected images with the origin in a no data pixel).

Using the following code block, I am able to perform a gaussian stretch on an image.

def gaussian_stretch(input_array, array_mean, array_standard_deviation, number_of_bins, n):
    shape = input_array.shape
    input_array = input_array.flatten()
    #define a gaussian distribution, get binned GDF histogram
    array_standard_deviation *= n
    gdf = numpy.random.normal(array_mean, array_standard_deviation, 10000)
    hist, bins = numpy.histogram(gdf, number_of_bins, normed=True)
    cdf = hist.cumsum()
    cdf = 256 * cdf / cdf[-1]
    #interpolate and reshape
    input_array = numpy.interp(input_array,bins[:-1],cdf)
    input_array = input_array.reshape(shape)
    return input_array

If the image does not contain a NoData border the stretch works as expected. On an image with a mask, the mask is ignored. Is this expected behavior? Any ideas on how to process only the unmasked data?

I have tried using input_array.compressed(), but this returns a 1D array of only the unmasked values. Using numpy.interp then fails, as expected, because of the size disparity between arrays.

Finally, I understand that using numpy.random.normal will not always return a perfect gaussian distribution and I will add some margin of error contraints once the rest of the algorithm is functioning.

  • 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-05-24T17:13:07+00:00Added an answer on May 24, 2026 at 5:13 pm

    you can get the mask of input_array first, and apply it to the result array, and use scipy.stats.norm to calculate cdf of normal distribution, or you can use scipy.special.erf() to calculate cdf by using the cdf formula of normal distribution:

    import scipy.stats as stats    
    def gaussian_stretch2(input_array, array_mean, array_standard_deviation, n):
        mask = input_array.mask
        n = stats.norm(array_mean, array_standard_deviation*n)
        return numpy.ma.array(n.cdf(input_array), mask=mask)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a PIL image into an array using NumPy. I
I'm using numpy to build pixel arrays. An 800x600 image is an 3-dimensional array
I am using matplotlib and numpy to make a polar plot. Here is some
Is it possible to perform multi-variate regression in Python using NumPy? The documentation here
I have the following code in Python using Numpy: p = np.diag(1.0 / np.array(x))
I'm using a numpy object_ array to store variable length strings, e.g. a =
Audio processing is pretty new for me. And currently using Python Numpy for processing
I am reading in a file using numpy.genfromtxt which brings in columns of both
So, I'm doing some Kmeans classification using numpy arrays that are quite sparse-- lots
I'm trying to using numpy.lib.stride_tricks.as_strided to iterate over non-overlapping blocks of an array, but

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.