ome / omero-figure

An OMERO.web app for creating Figures from images in OMERO
http://figure.openmicroscopy.org
GNU Affero General Public License v3.0
15 stars 31 forks source link

Polygon discrepancies pdf vs figure #455

Open pwalczysko opened 2 years ago

pwalczysko commented 2 years ago

See the figure on https://outreach.openmicroscopy.org/figure/file/173681/ . When exported as pdf, the lines in the figure are much less than on the pdf. Also, they protrude into the canvas on the pdf. Note that the images were intentionally rendered black just for the purpose of not exposing the figure images publicly before taking the screenshots below.

PDF:

Screenshot 2022-02-04 at 13 49 56

Figure: Screenshot 2022-02-04 at 13 49 00

pwalczysko commented 2 years ago

cc @will-moore

Tom-TBT commented 1 year ago

Looking into that issue, I haven't got a solution yet, but I thought writing down here what I figured before going on holiday.

First, the issue goes beyond. Shapes are checked whether inside the image or not, by looking at each point composing them. For example, if a square's corners are all outside the image but an edge still passes on top, the shape won't be displayed in the PDF:

https://github.com/ome/omero-figure/blob/13ccea055a45452f1c02272682dd75b142b1d41e/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py#L422

Example with a polygon on two views of the same image+ROI: OMERO.figure: image

PDF export: image

Regarding the shapes going outside of the image, this is because the drawing happens at the canvas level for PDF, independently from the image pasting (while TIFF has the shape pasted first on the image, then the modified image is pasted on the canvas):

https://github.com/ome/omero-figure/blob/13ccea055a45452f1c02272682dd75b142b1d41e/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py#L1937

Now I've been looking for a way to restrict PDF drawing to the boundaries of an image, but no success (keywords: reportlab canvas drawPath mask restrict crop) We could bother to calculate "new points" to be drawn, but that will bring many more issues when filling shapes (not mentioning text labels).

Instead, why not use the TIFF approach, and modify the images before drawing them on the PDF? The shape wouldn't be in the vector format anymore. But the resolution is supposed to match that of the image anyway, or? I found this comment, why is that? https://github.com/ome/omero-figure/blob/13ccea055a45452f1c02272682dd75b142b1d41e/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py#L1953

will-moore commented 1 year ago

@Tom-TBT Thanks for your input on this issue.

That comment: # ... but for PDF we have to add shapes to the whole PDF page reflects the approach that is currently taken, where we don't "paint" the ROIs onto the shapes for PDFs, but instead we add vector shapes to the PDF page.

I guess we could do as use suggest and paint the Shapes onto the panels as we do for TIFF export. That should fix this issue, but I wonder if many users would mind? How useful it is to have the Shapes as separate vectors on a PDF? Do users ever open the PDF figures in e.g. Illustrator and edit those Shapes? In cases where the panel is low resolution, they might not appear so nice if we paint them onto the images?

Tom-TBT commented 1 year ago

Found https://github.com/ome/omero-figure/issues/330, a suggestion from you to finalize PDF figure exports in a postscript editor. So removing completely the export of vectors could indeed be frustrating as it's an "official workaround"