Adding and editing an image

Hi guys,
A quick thank you to all who chipped in on previous issue. Got it sorted in the end with inputs from a number of people.
My next issue may be a simple one or not, but have tried to find solution with no luck.
I am trying to add an image and then edit it. What I want to do is slice the image into a number of strips, and separate the image strips a specified distance away from each other. The idea is to create a comb effect, and to be clear, I am not wanting to delete any part of the image, just to separate it into strips that if recombined, would make up the original image.
Any and all help is appreciated,


  • In the distant past I used a "gf2gds" program to get the image into layout tool. Which is probably not the proper name, but ....

    Import, put on appropriate layer etc.

    Then I'd use the Edit>Subtract others from first after overlaying "cutter" stripes where you want stuff gone.
  • edited September 16

    Cool solution :)

    I could not find a gf2gds program on the net.

    But here is a small piece of code turning an image into a layout:

    # Prepare a layout
    ly = pya.Layout()
    l1 = ly.layer(1, 0)
    top = ly.create_cell("TOP")
    # Load the image and convert to RGB32 for easy decoding
    img = pya.QImage("/home/matthias/Pictures/avatar.png")
    img = img.convertToFormat(pya.QImage.Format_RGB32)
    p = 1.0  # pixel size in micron
    # Scan the image and create a box for each "bright" pixel
    for x in range(0, img.width()):
      for y in range(0, img.height()):
        px = p * x
        py = p * (img.height() - 1 - y)
        # green pixel value determines if bit is set or not
        green = (img.pixel(x, y) >> 8) & 0xff
        if green >=128:
          top.shapes(l1).insert(pya.DBox(px, py, px + p, py + p))
    # Display the layout    
    mw = pya.MainWindow.instance()
    vw = mw.view(mw.create_view())
    vw.show_layout(ly, True)


  • Hi guys,
    Thanks for your help. I have used that gf2gds method and although it imports and you can make some changes, I cant seem to separate the image into strips, only delete the strips which I don't want to do. The image need to cut into strips and expanded out wards.
    Again, any help etc etc

  • Do these images look like what you want?

  • Yes!! Exactly!

  • OK. Then, the attached solution of mine will help.
    But you need to modify the lines shown below to reflect your environment.

    Good luck!

  • OK, thats sounds good. But you have to remember I am very much a novice at this. Do i save these files in the Klayout folder as a GDS file?

  • edited September 23

    Location of the three files

      A brief usage is given in the script, as shown below.

      If you are using KLayout on Window, the right place would be:

    2. avatar.png
      Any place. However, you need to set the full path to the image file in line 128 like:
      imgSrc = "C:/MyWork/avatar.png"

    3. KazzzS-KL2158A.lyp
      Any place.

    Step-by-step operations (Images captured on macOS)

    Saving the layout
    This script does not generate any output file in GDS2 or other formats.
    You can manually do so.
    Or you can add some more code to save the layout automatically. ===> Reference


  • Well that seems to have worked a treat as they say. I do have one question though. Is it possible to keep the image in its original colour? It has broken the image into three layers, each layer a whatever colour you choose, but I was hoping to keep the image as it was - in full colour.

Sign In or Register to comment.