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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:38:50+00:00 2026-05-30T12:38:50+00:00

How to put sequence (raw) data of one image into another which has different

  • 0

How to put sequence (raw) data of one image into another which has different size?
Visual effect expected to be as one of crop method but data should come as raw data

...
sequence = image1.getdata()
size=(int(image1.size[0]/2),int(image1.size[1]/2))
image2 = Image.new(image1.mode, size, "black")
seq_in=[]
for i in xrange(len(sequence)):
      seq_in.append(sequence[i])
seq_out=transform_data(seq_in,size,image1.size)
image2.putdata(seq_out)
...

following 2 variants of transformation give different results but not as would be expected

transform_data(seq_in,size,size_in):

#seq_t=do_something_with_the_data(seq_in)
seq_t=seq_in

seq_out=[]
#A:
sz=size[0]*size[1]
for i in xrange(sz):
      seq_out.append((seq_t[i]))
# end A
#B:
seq_r = numpy.array(seq_t).reshape(size_in[0],size_in[1],3)

for i in xrange(size[0]):
   for j in xrange(size[1]):
      seq_out.append((seq_r[i][j][0], seq_r[i][j][1], seq_r[i][j][2]))
#end B

return seq_out
  • 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-30T12:38:51+00:00Added an answer on May 30, 2026 at 12:38 pm

    You made it very hard for us to figure out what you’re trying to do (especially because you already told us the code you’ve included doesn’t work). But this is how I would do a crop:

    from PIL import Image
    import numpy as np
    
    size = image1.size
    size = [i//2 for i in size]
    array1 = np.asarray(image1)
    array2 = array1[:size[1], :size[0]]
    image2 = Image.fromarray(array2)
    

    Notice that array1 has shape (y, x, 3) if image1 has size (x, y). If you need to put the values from array2 into an existing image I believe the easiest way is:

    image2.fromstring(array2.tostring())
    

    Also in your code sequence is already a “sequence” (or it is iterable if you want to be technical) so you don’t need to create a seq_in, but if you really want to have sequence as a list, you can do seq_in = list(sequence)

    I still don’t quite understand the problem you’re having but maybe this example will help clear things up:

    image1 = Image.open("img1.jpg")
    array1 = np.asarray(image1)
    array2 = np.fft.fftn(array1)
    array2_uint = (np.log(np.abs(array2)) * 14).astype('uint8')
    image2 = Image.fromarray(array2_uint)
    array3 = np.fft.ifftn(array2).astype('uint8')
    image3 = Image.fromarray(array3)
    

    Image1

    image1

    Image2

    image2

    Image3

    image3

    As you can see both array2_uint and array3 get correctly converted to images. Can you try and explain the problem you’re having, maybe update the code in your question to include an example or the wrong output if you’re getting the wrong output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Put them all in one separate folder structure or along with classes which implements
Hey, trying to put a simple png sequence animation into my app. I have
I have some data that I export into an XML file and put in
Is there any constraint onto compareTo method which orders objects put into the standard
In the first one, I put the minOccurs and maxOccurs in the sequence element:
Two Questions: Will I get different sequences of numbers for every seed I put
Put it another way: what code have you written that cannot fail. I'm interested
Given a sequence,say, 222 We have to put a '+' or '* ' between
I have to present 4 view controllers in sequence. One is the continuation of
Related to this SO question , I want to put the data loading in

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.