How to compare two PIL.Image JPEG photos (same size) using SSIM or a similar algorithm compatible with "pure python" or Pythonista? - python-3.x

I know that similar questions have been asked many times, but still I have not found a satisfactory answer for what I am looking for. I want to be able to compare two versions of the same image, in order to detect the amount of perceptual artifacts resulting from JPEG compression, without any further changes (i.e., no crops, no rotation...). I mean, not just the histogram or the number of pixels that are different (those would be probably easy to get from Pillow), but instead I would like to be able to obtain some kind of measure of their overall visual impact.
Reading through some articles in SO and in other places, I have found multiple references to SSIM algorithm, that seems to do precisely what I am looking for. There is even a Python (https://github.com/jterrace/pyssim), but the problem is that all those implementations seem to depend on packages that can't be installed in some of my target devices. I am using Pythonista 3 on iOS, which includes Pillow 2.9.0 and numpy, but scipy (required by pysimm) is not compatible.
Is there any other viable way to calculate SIMM or a similar comparison value that does not require anything more that Python 3.6, Pillow and/or Numpy 1.8.0?

Related

Is it normal for your gpu device not to support three channel formats?

I've noticed that the GPU I'm running on Vulkan doesn't support so many of the R8G8B8_UINT formats but does with the R8G8B8A8 FORMATS. Also the same thing with many others like R32G32B32_SFLOAT. I've noticed that's also the with other GPUs I've seen on OpenGPU database.
Is this normal? Why is this so? Is it normal with other graphics APIs? Is it to align values/texels to a "round/nicer/aligned" number of bytes? How are you supposed to get around this? I'm having trouble seeing how throughout your code you'll be interacting with images that you have no idea what colour format they are, which complicates things both on host code and in shaders.
Also if I have 3 channel colour format image on the host and I want to use with Vulkan and say R8G8B8 or R32G32B32, do I need to loop through the image manually and rearrange the texels?
24bpp formats are hard to optimize in graphics hardware. This is why there is no "R8G8B8" format even defined for the DirectX Graphics Infrastructure pixel formats used for Direct3D 10, 11.x, and 12. Almost all the work is around optimizing 32bpp formats which is why RGBA32, BGRA32, etc. are much more commonly supported. 64bpp and 128bpp formats are multiples of 32-bits, so it makes just the 24bpp format the 'odd-man out' in many cases. You often can find a B8G8R8X8 (32-bit) format which is about as close as you get to 24bpp.
Some hardware will find ways to support 24bpp formats (which were supported by older Direct3D releases for example), but it's generally less efficiently rendered.
Similar issues arise with 96bpp formats (R32G32B32 floating-point). For Direct3D Hardware Feature Levels, this format is always optional and when implemented it's typically done as three 32-bit floating-point planes, one for each color channel.

VTK: display integration point data

I'm working with the VTK library in C++.
I have a mesh given as an unstructured grid and certain data given on integration points of gaussian quadrature on the cells (which was created by an external solver). For the sake of simplicity, let's assume that we talk about scalar data.
I also have a tool which displays VTK data graphically. What I want is to display the mentioned data with that tool, simply as interpolated/extrapolated scalar data on the whole grid.
My question is, is there something native to VTK with which I can give the mesh the scalar data at the integration points in some way and VTK handles the interpolation and extrapolation?
I mean, I could write an algorithm that processes the data, creates a new grid in which the cells do not share nodes (as the extrapolated values might not be continuous there), extrapolate the scalars to those nodes for each cell and then display that. However, by this I take away from the native possibilities of the VTK library (which seems to be quite strong in most other regards) and I don't want to reinvent the wheel anyway.
From https://vtk.org/Wiki/images/7/78/VTK-Quadrature-Point-Design-Doc.pdf, I am aware that there is the vtkQuadratureSchemeDefinition class and I think I know how to handle it, and I noticed vtkQuadraturePointInterpolator, which seems to do the opposite of what I'm searching for - interpolation to the integration points rather than extrapolating from them.
The newest entry in the VTK wiki otherwise seems to be https://vtk.org/Wiki/VTK/VTK_integration_point_support, which seems to be quite old, given that it pleads for the existence of some sort of quadrature point support in general, which currently already exists.
Also there is a question in the VTK mailing list which looks just like my question here:
https://public.kitware.com/pipermail/vtkusers/2013-January/078077.html, which seems to be without an answer.
Likewise, the issue https://gitlab.kitware.com/vtk/vtk/issues/17124 also seems to be about what I want to do, and it might hint at it currently not being possible, but it existing as an issue does not imply that it is not already solved (especially with no asignee to the issue).

Easiest way to generate depth image/map from 3d model

I was wondering if anybody knew of an easy, robust way to generate depth images from 3d models (i.e. surface models, vertices with faces), with specifiable camera parameters.
I'd prefer "free" options if possible (e.g. pyOpengl or some open source Java library rather than say matlab).
I believe it is possible with the python blender api (noted here), but I'm hoping there's an easier way.
Note also that this question works only for that special case.
You can use DECA repository in Github. There, in ./demos, I used demo_reconstruct.py code to save the depth image.

VTK alternatives

I apologize if the answer was already somewhere, searching the interwebs did not return me the answer(s) I was looking for.
Situation : I have a small graph (a set of Edges and Nodes that is) - Now I want to display it in an interactive manner, and I would like to manipulate the display styles and symbols that are used for edges and nodes, programetically.
Hence kgraphviewer wont work - i want to do it programetically as stated.
I noticed VTK, comes with a lot of built is graph drawing algorithms. But seems to be a really large one.
Question : What are some alternatives to VTK ? Graphviz is probably one, but I can not confirm that graphviz comes with all the graph drawing algorithms as VTK - any other possibly smaller options, with all the built in graphs?
Side note : Some systems uses a static drawign widget, i.e. once the drawing is displayed, in an widget that the system comes with, you can not interact with the drawing using your mouse. The GNU implementation of IDL, GDL, has this problem. I would Like to avoid this.
Yes, I agree with you regarding the VTK's consideration: it's a powerful toolkit but it is (maybe) too much "big", and it's not so easy to configure a working VTK environment.
I don't have a great experience in the field of graphs, but a search leads to this other StackOverflow post. I think that Prefuse, listed under the Java section, could be of some interest. C++ itself seems to have a lot of choices, listed in various answers, here. I hope that it will help.
I used Gephi public domain graph visualization software on Linux. It was a quick way to get a 3 D. Picture which can be modified with line thickness to show an edge weight - good for comm network work.

Boolean Operations on Cairo Paths?

Is there any way to build paths in Cairo by combining two paths together through Boolean operations such as Union, Difference, and Intersection? I'm working on a vector graphics application that uses Cairo to do its rendering and would like to give my users the ability to combine paths together in this manner, but I can't find a way to do it in Cairo.
I haven't found a way to do this with the cairo libraries. But it's a feature I've been looking for too. Would definitely be helpful when (for example) stroking the combination of two paths - compositing operators mentioned by ntd don't seem to be able to do this.
In the meantime, I'm trying to write scripts for inkscape, and letting inkscape do the unioning/differencing. Acceptable for the problem I'm working on but definitely not for yours. Have you had any luck, either with cairo or any other svg library? After a couple days of googling, it doesn't seem to be trivial :/
Combining paths with operators does not make any sense to me. What do you get from "line AND curve OR arc"?
Instead, you can apply compositing operators by using cairo_set_operator(): it will set how the current drawing operation (being it cairo_fill(), cairo_stroke() or whatever) should be mixed with the old content of the surface.

Resources