1

I need to take the central part of an image and zoom it keeping the same dimensions of the original image. I've been able to zoom a part of image keeping the same dimensions of image, but I don't understand because this part isn't the central part.

This is the code:

def zoom(source,x):
#@param source:Picture;
#@param x:int; the value to scale up the image;


   target=makeEmptyPicture(getWidth(source),getHeight(source))

   width=getWidth(source)
   height=getHeight(source)

   Xseq = []
   Yseq = []

   colCentrale=x/2    #central column
   rigCentrale=x/2    #central row

   Xseq = []
   for sourceX in range(colCentrale*(width/x),(colCentrale*(width/x))+(width/x)):
       for n in range(0,x):
           Xseq = Xseq+[sourceX]

   Yseq = []
   for sourceY in range(rigCentrale*(height/x),(rigCentrale*(height/x))+(height/x)):
       for m in range(0,x):
           Yseq = Yseq+[sourceY]




   targetX=0
   for sourceX in Xseq:
       targetY=0
       for sourceY in Yseq:
           color = getColor(getPixel(source,sourceX,sourceY))
           setColor(getPixel(target,targetX,targetY),color)
           targetY = targetY + 1
       targetX = targetX + 1

   show(target)
Peter
  • 11
  • 4

0 Answers0