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 7601693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:13:36+00:00 2026-05-30T23:13:36+00:00

I have an image which consists of two arbitrarily placed black 1px blobs on

  • 0

I have an image which consists of two arbitrarily placed black 1px “blobs” on a white canvas 100px by 200px. I’m trying to “blur these blobs by turning some of the neighbouring pixels (within a radius of 10px of each blob) black also. I’ve put together the following code, but am not quite sure of the next step..

import numpy as np
from PIL import Image 
from scipy import ndimage
from matplotlib import pyplot
from matplotlib import cm
from scipy.misc import imsave

im = Image.open("test.png")
pix = np.asarray(im)
new_pix = np.copy(pix[:,:,0]) # need this otherwise can't write to the pix array.
pix_to_enlarge = np.where(new_pix != 255)
pixels_to_enlarge_by = 10
i=0
for each_pixel in pix_to_enlarge[0]: # this cycles through each non-white pixel
    for y in range(len(new_pix)): # this looks across the length (down) the page
        for x in new_pix[y]: # this looks across the x-axis for each y step
            radius = pixels_to_enlarge_by**2

so essentially I’ve found the locations of the non-white pixels in the variable pixels_to_enlarge_by. What I’m trying (and so far failing to do) is to select the surrounding pixels (within 10px) and change them to black also. Any ideas?

  • 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-30T23:13:37+00:00Added an answer on May 30, 2026 at 11:13 pm

    In one way or the other you need to look at each pixel and then figure out how much of that content you want to distribute to each other pixel in your picture, for example by comparing the distance between the two.

    Here’s how it’s done with numpy. If you want to do it manually then that may in any case help as a starting point. It’s called convolution.
    2d convolution using python and numpy

    Here’s a good starting point about gaussian blur:
    http://en.wikipedia.org/wiki/Gaussian_blur

    But if you just want to make a on/off blurring effect then the function to convolve with (convolution kernel) is just an if statement on the distance between the source point and any possible neighbor pixel. For sure there are optimizations for that case: your loops will not need to span all pixels for all pixels, only enough so that a circle of size R fits within the range considered.

    Since you want first principles, here it is. It works only for rgb black and white

    from PIL import Image 
    
    im = Image.open("cat2.png")
    px=im.load()
    im2 = im.copy()
    px2=im2.load()
    sx,sy=im.size
    def turnpixel(Nix,Niy):
        for ix in range(sx):
            for iy in range(sy):
                r2=(Nix-ix)**2+(Niy-iy)**2
                if r2<5:
                    if sum(px[ix,iy])>100: # rgb sum>100 is considered ON.
                        px2[Nix,Niy]=(255,255,255)                            
                        return
                        # we turned a pixel on, so we are done with it.
    
    for Nix in range(sx):
        for Niy in range(sy):
            px2[Nix,Niy]=(0,0,0)
            turnpixel(Nix,Niy)
    
    im.show()
    im2.show()
    

    If you want a smoothing that is a function of the distance use something like

    import math
    def turnpixel(Nix,Niy):
        for ix in range(sx):
            for iy in range(sy):
                r=int(math.sqrt((Nix-ix)**2+(Niy-iy)**2))
                def convfunc(o,v):
                    return o+int(v/(r*20+1))
                px2[Nix,Niy]=tuple(map(convfunc,px2[Nix,Niy],px[ix,iy]))
                if sum(px2[Nix,Niy])>=3*250:
                    return
    

    Obviously, you should operate on floats, not integers if you do stuff like this. And use numpy or some of the image manipulation modules.

    Gaussian blur would be (within the function above). Now integer is a really bad idea btw:

            inv2sigma2=1.0/(2*3)
            r2=(Nix-ix)**2+(Niy-iy)**2
            fact=inv2sigma2/(math.pi)*math.exp(-r2*inv2sigma2)
            def convfunc(o,v):
                return o+int(v*fact)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image which is placed in the middle of the screen all
I have an image which is pretty much b&w and it has a black
I have a MenuButton which consists of a Image and a Text under the
I have an image which I use to frame a tweet. It consists of
I have a image which has an mouseover jquery function: $(document).ready(function ()) { mouseenter:
I have an image which is made up of 2 images, a sprite. What
I have an Image which I am translating along the X , with the
I have an image which is just made of one color ? (it could
I have an image which is added to the project. In the simulator it
Does libjpeg allows/have routines to scale the output image? I have an image which

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.