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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:29:29+00:00 2026-05-22T14:29:29+00:00

I am working in image processing right now in python using numpy and scipy

  • 0

I am working in image processing right now in python using numpy and scipy all the time. I have one piece of code that can enlarge an image, but not sure how this works.

So please some expert in scipy/numpy in python can explain to me line by line. I am always eager to learn.

import numpy as N
import os.path
import scipy.signal
import scipy.interpolate
import matplotlib.pyplot as plt
import matplotlib.cm as cm


def enlarge(img, rowscale, colscale, method='linear'):
    x, y = N.meshgrid(N.arange(img.shape[1]), N.arange(img.shape[0]))
    pts = N.column_stack((x.ravel(), y.ravel()))
    xx, yy = N.mgrid[0.:float(img.shape[1]):1/float(colscale),
            0.:float(img.shape[0]):1/float(rowscale)]
    large = scipy.interpolate.griddata(pts, img.flatten(), (xx, yy), method).T
    large[-1,:] = large[-2,:]
    large[:,-1] = large[:,-2]
    return large

Thanks a lot.

  • 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-22T14:29:30+00:00Added an answer on May 22, 2026 at 2:29 pm

    First, a grid of empty points is created with point per pixel.

    x, y = N.meshgrid(N.arange(img.shape[1]), N.arange(img.shape[0]))
    

    The actual image pixels are placed into the variable pts which will be needed later.

    pts = N.column_stack((x.ravel(), y.ravel()))
    

    After that, it creates a mesh grid with one point per pixel for the enlarged image; if the original image was 200×400, the colscale set to 4 and rowscale set to 2, the mesh grid would have (200*4)x(400*2) or 800×800 points.

    xx, yy = N.mgrid[0.:float(img.shape[1]):1/float(colscale),
            0.:float(img.shape[0]):1/float(rowscale)]
    

    Using scipy, the points in pts variable are interpolated into the larger grid. Interpolation is the manner in which missing points are filled or estimated usually when going from a smaller set of points to a larger set of points.

    large = scipy.interpolate.griddata(pts, img.flatten(), (xx, yy), method).T
    

    I am not 100% certain what the last two lines do without going back and looking at what the griddata method returns. It appears to be throwing out some additional data that isn’t needed for the image or performing a translation.

    large[-1,:] = large[-2,:]
    large[:,-1] = large[:,-2]
    return large
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an image processing application where I have two threads on top
I am working on image processing . I have a buffered image of fixed
Right now I'm working on a program for my Visual Information Processing course. We're
I am new in c#. I am working on image processing. I am creating
I'm currently working on a project for medical image processing, that needs a huge
I am working on a project that requires some image processing. The front end
I'm working the the image upload piece of the FCKEditor and I've got the
I am working on an image generation script in PHP and have gotten it
I'm working with an image processing project where I'm trying to locate features on
I am currently working on an image processing demonstration in java (Applet). I am

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.