Tagged: nazca.image
- This topic has 3 replies, 2 voices, and was last updated 2 years, 6 months ago by Wiebke Jahr.
-
AuthorPosts
-
5 June 2022 at 20:51 #6804Wiebke JahrParticipant
I am trying to convert a .png image to .gds using nazca. Among other structures, the image has two concentric circles.
When the small inner circle is white, the large circle is black, and the image background is white, conversion failes and only the inner white circle is exported on dark background. However, when the image is inverted (black small circle, white large circle, black background), the conversion works as expected.
I’m attaching two screenshots of the behaviour, also showing the image as imported with the underlying PIL library, which is still displayed correctly, so I think the error is happening in the file format conversion.
Is this a bug, or expected behaviour? I have no experience with PICs, so I am not sure about “expected use cases”.
Here’s my source code:
import nazca as nz import matplotlib.pyplot as plt from PIL import Image fn = "MWE_circ" img = Image.open(fn+".png") _=plt.imshow(img) fn = "MWE_circ" nz.image(fn+".png").put() nz.export_plt()
5 June 2022 at 23:55 #6808XaveerModeratorDear Wiebke,
Your code should yield the correct result, provided the nazca version is sufficiently new (>= 0.5.13). For that version, make sure that pyclipper is installed (see step 3. of the installation instructions, https://nazca-design.org/installation/).
For newer versions of nazca, you can alternatively use the ‘merge=False’ argument to the nazca.image() call.
Xaveer
6 June 2022 at 16:18 #6810Wiebke JahrParticipantDear Xaveer,
As you’ve seen from the registration mail, I had previously tried with pyclipper installed, but then uninstalled it when I ran into the bug. I’m pasting the original question from my email here, so anyone who runs into the issue the info also in the forum.
I’m trying to convert an image to gds. Without pyclipper installed, conversion completes, but the gds file is missing some of the structures. With pyclipper installed, I get the following error message:
nz.image(fn+”.png”,
4 size = 8992, pixelsize = 2.7, threshold = 0.5,
5 cellname = ‘SP’).put()File ~\Anaconda3\envs\nazca\lib\site-packages\nazca\bb_util.py:1622, in image(name, layer, size, pixelsize, threshold, cellname, invert, align, box_layer, box_buf)
1620 xy = [(x0, y0), (x1, y0), (x1, y0 – p), (x0, y0 – p)]
1621 polygons.append(xy)
-> 1622 for pol in nd.clipper.merge_polygons(polygons):
1623 nd.Polygon(points=pol, layer=layer).put()
1625 if box_layer is not None:File ~\Anaconda3\envs\nazca\lib\site-packages\nazca\clipper.py:269, in merge_polygons(paths, accuracy)
267 clipper.AddPaths(st(paths, sc), pc.PT_SUBJECT, True)
268 mp = clipper.Execute(pc.CT_UNION, pc.PFT_NONZERO, pc.PFT_NONZERO)
–> 269 mp = _clipper2GDS(mp)
270 for p in rev:
271 p.reverse()File ~\Anaconda3\envs\nazca\lib\site-packages\nazca\clipper.py:230, in _clipper2GDS(clipper_result)
227 for i, pi in enumerate(inner): # Remove each hole from the outer polygon
228 if i in todo and pc.PointInPolygon(pi[0], po):
229 # Subtract with tether.
–> 230 po = _subtract_polygon(po, pi)
231 todo.remove(i)
232 result.append(po)File ~\Anaconda3\envs\nazca\lib\site-packages\nazca\clipper.py:186, in _subtract_polygon(XYo, XYi)
184 xo, yo = x, y
185 # Construct polygon
–> 186 poly = XYo[0:ndxo] + [point] + XYi[ndxi:] + XYi[0:ndxi + 1] + [point] + XYo[ndxo:]
187 return polyUnboundLocalError: local variable ‘ndxo’ referenced before assignment
I checked the source code, and it seems it never jumps into the if-condition starting at line 180? I have two concentric circles in the design, the smaller one white, the larger one black, could they be causing the issue
for i, (x, y) in enumerate(XYo[1:]):
# print(f”{i} -> {i+1}: {(xo, yo)} -> {x, y}”)
if yo >= yp and y <= yp and (xo < xp or x < xp):
# Line segment intersecting with horizontal.
# Calculate distance to intersection point
xi = _x_intersect((xo, yo), (x, y), yp)
d = xp – xi
if d > 0 and d < dmin:
dmin = d
ndxo = i + 1
point = (xi, yp)
xo, yo = x, y
# Construct polygon
poly = XYo[0:ndxo] + [point] + XYi[ndxi:] + XYi[0:ndxi + 1] + [point] + XYo[ndxo:]
return polyI then tried with the new version of Nazca you sent via email and re-installed pyclipper. Indeed, the error message is gone now and conversion completes. However, the behaviour is unchanged: in the white background / black outer circle / white inner circle, only the inner circle is shown, whereas for the inverted blac background / white outer circle / black inner circle, all structures are converted.
I am now working around the problem by first inverting the .png image, and then using
nz.image(fn+”.png”, invert=True).put()
which works for my immediate problem.
Thank you!
- This reply was modified 2 years, 6 months ago by Wiebke Jahr.
7 June 2022 at 19:10 #6812Wiebke JahrParticipantSOLVED:
issue is with transparencies in the .png, not with inversion of white / black. The “white background” was in fact transparent.
-
AuthorPosts
- You must be logged in to reply to this topic.