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
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:
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:
Also in your code
sequenceis 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 doseq_in = list(sequence)I still don’t quite understand the problem you’re having but maybe this example will help clear things up:
Image1
Image2
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.