Illegal instruction when changing node shape - graphviz

I followed the instructions here to change the default node shape: How to set default node shape to box instead of oval?
Input file:
digraph Blah {
rankdir="LR"
node [shape="box"];
A -> B -> C;
B -> D;
}
I then use the command dot -v -Txdot gt.dot > gt.xdot.
Output (verbose):
dot - graphviz version 2.44.0 ()
libdir = "/usr/lib/graphviz"
Activated plugin library: libgvplugin_core.so.6
Using render: xdot:core
Using device: xdot:xdot:core
Activated plugin library: libgvplugin_dot_layout.so.6
Using layout: dot:dot_layout
The plugin configuration file:
/usr/lib/graphviz/config6
was successfully loaded.
render : cairo dot dot_json fig json json0 map mp pic pov ps svg tk visio vml xdot xdot_json
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : canon cmap cmapx cmapx_np dot dot_json eps fig gv imap imap_np ismap json json0 mp pdf pic plain plain-ext png pov ps ps2 svg svgz tk vdx vml vmlz x11 xdot xdot1.2 xdot1.4 xdot_json xlib
loadimage : (lib) eps gif jpe jpeg jpg png ps svg
pack info:
mode undefined
size 0
flags 0
margin 8
pack info:
mode node
size 0
flags 0
fontname: "Times-Roman" resolved to: (ps:pango FreeSerif, REGULAR) (PangoCairoFcFont) "FreeSerif, Regular" /root/.fonts/FreeSerif.otf
Illegal instruction
But, when I remove the node [shape="box"]; line, it works. What am I doing wrong?

[this file worked correctly on my linux system with two versions of Graphviz]
You aren't doing anything wrong, but your font library info may be messed up?
/root/.fonts seems like a weird place for fonts.
What is the -v output when you use the default node shape? Does it still reference /root/.fonts?

Related

Exiftool from remote sources

I'm trying to get image metadata from the internet using exiftool and tried to follow along with the piping example provided in exiftools docs, which I've linked below. This does not work as expected and instead returns an error of no file specified. I've tried putting the URL into quotes, changing around the command to use curl as an input into exiftool instead of piping, nothing seems to work. Any help would be appreciated.
https://exiftool.org/exiftool_pod.html#PIPING-EXAMPLES
Works just fine for me. Make sure to add the - to indicate reading from stdin. Here is an example:
> curl -s "https://www.gravatar.com/avatar/1f20f72dba83a169c623fbe652657a32?s=48&d=identicon&r=PG" | exiftool -
ExifTool Version Number : 11.88
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 48
Image Height : 48
Bit Depth : 8
Color Type : RGB with Alpha
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
Pixels Per Unit X : 3780
Pixels Per Unit Y : 3780
Pixel Units : meters
Image Size : 48x48
Megapixels : 0.002

Graphviz not rendering node image

despite using the most simple boilerplate I can find, I can't seem to get graphviz to render a png image onto a node
Some may consider this a duplicate of How do I get DOT to display an image for a node? however this is the question I was following to get to this point and it STILL doesn't work
I've tried rendering already in several programs including vscode's preview extension, the dot -Tpng graph.png chickens2.dot -v command line method, and GVEdit and none of them correctly render the image into the node
here is my code
digraph graph1 {
node [shape=record];
white [image="dye_powder_white.png", label=""];
}
and the folder structure
Chickens/
|chickens2.dot
|dye_powder_white.png
I wanted it to simply show the icon inside of the node, but it just renders a blank node.
here is the output from dot.exe:
>dot -Tpng -o graph.png chickens2.dot -v
dot - graphviz version 2.38.0 (20140413.2041)
Using render: cairo:cairo
Using device: png:cairo:cairo
libdir = "C:\Program Files (x86)\Graphviz2.38\bin"
Activated plugin library: gvplugin_dot_layout.dll
Using layout: dot:dot_layout
The plugin configuration file:
C:\Program Files (x86)\Graphviz2.38\bin\config6
was successfully loaded.
render : cairo dot fig gd gdiplus map pic pov ps svg tk vml vrml xdot
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : bmp canon cmap cmapx cmapx_np dot emf emfplus eps fig gd gd2 gif gv imap imap_np ismap jpe jpeg jpg metafile pdf pic plain plain-ext png pov ps ps2 svg svgz tif tiff tk vml vmlz vrml wbmp xdot xdot1.2 xdot1.4
loadimage : (lib) bmp eps gd gd2 gif jpe jpeg jpg png ps svg
pack info:
mode undefined
size 0
flags 0
margin 8
pack info:
mode node
size 0
flags 0
fontname: "Times-Roman" resolved to: (ps:pango Times New Roman, ) (PangoCairoWin32Font) "Times New Roman, 13.9990234375"
network simplex: 1 nodes 0 edges maxiter=2147483647 balance=1
network simplex: 1 nodes 0 edges 0 iter 0.00 sec
Maxrank = 0, minrank = 0
mincross: pass 0 iter 0 trying 0 cur_cross 0 best_cross 0
mincross graph1: 0 crossings, 0.00 secs.
network simplex: 1 nodes 0 edges maxiter=2147483647 balance=2
network simplex: 1 nodes 0 edges 0 iter 0.00 sec
routesplines: 0 edges, 0 boxes 0.00 sec
Using render: cairo:cairo
Using device: png:cairo:cairo
dot: allocating a 19K cairo image surface (83 x 60 pixels)
gvRenderJobs graph1: 0.00 secs.
here is the exact png image I'm trying to embed just in case it's incompatible with graphviz and I don't realize:
https://mega.nz/#!M8EHEITJ!Mm489BA4sd5JLoeWlY7BM-YCIkHeAni96d-e1IY4UAQ
and finally, the resulting image which is the same in every method I've tried:
https://i.imgur.com/IcIJSMA.png
some things I'm considering:
is there some kind of configuration I'm not seeing which disables images by default?
do I have some kind of outdated version? (literally downloaded the stable this morning to try it out so I doubt it)
am I simply doing something wrong?
are graphviz images incompatible with windows 10?
am I missing a prerequisite library?
is my png image incompatible with graphviz somehow?
I've been trying this for an hour or so now and none of my attempts seem to be changing anything.
what is the correct way to get graphviz to render an image onto a node?
Old question, but I also couldn't figure this out. The attribute image doesn't seem to work as expected, and the manpage doesn't help, nor do the docs. Posting what worked for me for others who come across this question.
This answered it for me, from 2011. For example, in some image.gv file:
digraph {
ratio="fill";
size="10,10!";
margin="0,0";
node [shape=plain];
root [label=<<TABLE border="0"><TR><TD><IMG SRC="image.png"/></TD></TR>
<TR><TD>text under</TD></TR></TABLE>>];
}

How to determine an image's encoding

I have an image with a PNG extension.
I suspect it's not really a PNG though (I think it might be a GIF).
How can I confirm an image's encoding?
NB: A solution for Windows would be preferable
on Linux, you can use file command
$ file branches.gif
branches.gif: PNG image data, 1257 x 782, 8-bit/color RGBA, non-interlaced
or ImageMagick part called identify
identify branches.gif
branches.gif PNG 1257x782 1257x782+0+0 8-bit sRGB 114KB 0.000u 0:00.000
You need to do a quick check of the file's internals.
The first 8 bytes of a PNG image are always
137 80 78 71 13 10 26 10
It is vanishingly unlikely that a non-malicious non-PNG has the same 8 bytes.
For windows open the file in a text editor, e.g. Sublime, and the first part should be the png magic number 89 50 4e 47 0d 0a 1a 0a.
One can use https://exiftool.org/ (gratis, portable, works on Microsoft Windows, macOS and Linux).
Demo, running the command exiftool.exe test.png in cmd:
Microsoft Windows [Version 10.0.19042.1706]
(c) Microsoft Corporation. All rights reserved.
C:\PortableProgs\exiftool-12.44>"exiftool(-k).exe" test.png
ExifTool Version Number : 12.44
File Name : test.png
Directory : .
File Size : 1837 kB
Zone Identifier : Exists
File Modification Date/Time : 2022:08:07 17:15:39-07:00
File Access Date/Time : 2022:08:07 18:55:55-07:00
File Creation Date/Time : 2022:08:07 18:55:55-07:00
File Permissions : -rw-rw-rw-
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 2123
Image Height : 1134
Bit Depth : 8
Color Type : RGB with Alpha
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
SRGB Rendering : Perceptual
Gamma : 2.2
Pixels Per Unit X : 9448
Pixels Per Unit Y : 9448
Pixel Units : meters
Exif Byte Order : Big-endian (Motorola, MM)
Orientation : Horizontal (normal)
Date/Time Original : 2022:08:07 14:24:32
User Comment : Screenshot
Color Space : sRGB
Exif Image Width : 2160
Exif Image Height : 1620
XMP Toolkit : XMP Core 6.0.0
Date Created : 2022:08:07 14:24:32
Image Size : 2123x1134
Megapixels : 2.4
-- press ENTER --

How to read jpeg image with Adobe RGB colorspace in OpenCV?

I am trying to read and write jpegs wth Adobe RGB colorspace in OpenCV. OpenCV assumes the jpeg has sRGB colorspace and when displaying or writing to file, the image loses some of its color intensity. I found this intensity loss was due to colorspace difference by answers given to my previous question.
Is there anyway I can make OpenCV to read Adobe RGB colorspace without casting it to sRGB?
Some information that is hopefully useful for anyone looking for a work-around for dealing with ICC and other profiles...
You can see what profiles are present in an image using ImageMagick which is installed on most Linux distros and is available for macOS and Windows. In the Terminal, or Command Prompt on Windows, run:
magick identify -verbose frog.jpg | grep 'Profile-.*bytes'
Profile-icc: 578 bytes
That tells you this image has a 578 byte ICC profile embedded.
If you are on Windows and don't have grep, you can equally use the following, though you may need to double up the percent sign, or prefix it with a caret (^) or somehow escape it:
magick identify -format "%[profiles]" frog.jpg
icc
You can extract that profile from the image, using this command:
magick frog.jpg frog.icc
And, you'll get a 578 byte ICC profile:
ls -l *icc
-rw-r--r-- 1 mark staff 578 24 Apr 10:36 frog.icc
You can check that the profile looks correct using the file command:
file *icc
frog.icc: ColorSync color profile 2.1, type ADBE, RGB/XYZ-mntr device by ADBE, 560 bytes, 11-8-2000 19:51:59 "Adobe RGB (1998)"
You can apply that profile to some other file like this:
magick other.jpg -profile "icc:frog.icc" otherWithProfile.jpg
Once you have extracted the profile using the above method, you can apply it to an image that you plan to use with OpenCV using PIL/Pillow's ImageCMS Module.
For that, I think you need to use these steps or something very similar, though I have not tested it:
from PIL import Image, ImageCMS
import numpy as np
# Open frog with PIL/Pillow
im = Image.open('frog.jpg')
iccp = PIL.ImageCms.getOpenProfile("profile.icc")
rgbp = ImageCms.createProfile("sRGB")
icc2rgb = ImageCms.buildTransformFromOpenProfiles(rgbp, iccp, "RGB", "RGB")
result = ImageCms.applyTransform(im, icc2rgb)
You should then be able to convert the resulting image to a Numpy array that OpenCV can work with using:
OpenCVim = np.array(result)
and remember to then convert from RGB ordering to BGR with cv2.cvtColor().
Rather than detect and extract the ICC profile with ImageMagick, you could equally use PIL/Pillow like this:
from PIL import Image
im = Image.open('frog.jpg')
# Now look at "im.info"
{'jfif': 257,
'jfif_version': (1, 1),
'dpi': (72, 72),
'jfif_unit': 1,
'jfif_density': (72, 72),
'icc_profile': b'\x00\x00\x020ADBE\x02\x10\x00\x00mntrRGB XYZ \x07\xd0\x00\x08\x00\x0b\x00\x13\x003\x00;acspAPPL\x00\x00\x00\x00none\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\xd6\x00\x01\x00\x00\x00\x00\xd3-ADBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ncprt\x00\x00\x00\xfc\x00\x00\x002desc\x00\x00\x010\x00\x00\x00kwtpt\x00\x00\x01\x9c\x00\x00\x00\x14bkpt\x00\x00\x01\xb0\x00\x00\x00\x14rTRC\x00\x00\x01\xc4\x00\x00\x00\x0egTRC\x00\x00\x01\xd4\x00\x00\x00\x0ebTRC\x00\x00\x01\xe4\x00\x00\x00\x0erXYZ\x00\x00\x01\xf4\x00\x00\x00\x14gXYZ\x00\x00\x02\x08\x00\x00\x00\x14bXYZ\x00\x00\x02\x1c\x00\x00\x00\x14text\x00\x00\x00\x00Copyright 2000 Adobe Systems Incorporated\x00\x00\x00desc\x00\x00\x00\x00\x00\x00\x00\x11Adobe RGB (1998)\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00XYZ \x00\x00\x00\x00\x00\x00\xf3Q\x00\x01\x00\x00\x00\x01\x16\xccXYZ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00XYZ \x00\x00\x00\x00\x00\x00\x9c\x18\x00\x00O\xa5\x00\x00\x04\xfcXYZ \x00\x00\x00\x00\x00\x004\x8d\x00\x00\xa0,\x00\x00\x0f\x95XYZ \x00\x00\x00\x00\x00\x00&1\x00\x00\x10/\x00\x00\xbe\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}
Here's the frog.jpg image:
Keywords: Python, ImageMagick, image, image processing, profile, ICC profile, extract, insert, apply, transform, PIL, Pillow, OpenCV, CMS, pyCMS.

Determine bit depth of bmp file on os x

How can I determine the bit depth of a bmp file on Mac OS X? In particular, I want to check if a bmp file is a true 24 bit file, or if it is being saved as a greyscale (i.e. 8 bit) image. I have a black-and-white image which I think I have forced to be 24 bit (using convert -type TrueColor), but Imagemagick gives conflicting results:
> identify -verbose hiBW24.bmp
...
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
> identify -debug coder hiBW24.bmp
...
Bits per pixel: 24
A number of other command-line utilities are no help, it seems:
> file hi.bmp
hi.bmp: data
> exiv2 hiBW24.bmp
File name : hiBW24.bmp
File size : 286338 Bytes
MIME type : image/x-ms-bmp
Image size : 200 x 477
hiBW24.bmp: No Exif data found in the file
> mediainfo -f hi.bmp
...[nothing useful]
If you want a commend-line utility try sips (do not forget to read the manpage with man sips). Example:
*terminal input*
sips -g all /Users/hg/Pictures/2012/03/14/QRCodeA.bmp
*output is:*
/Users/hg/Pictures/2012/03/14/QRCodeA.bmp
pixelWidth: 150
pixelHeight: 143
typeIdentifier: com.microsoft.bmp
format: bmp
formatOptions: default
dpiWidth: 96.000
dpiHeight: 96.000
samplesPerPixel: 3
bitsPerSample: 8
hasAlpha: no
space: RGB
I think the result contains the values you are after.
Another way is to open the image with the previewer preview.app and the open the info panel.
One of the most informative programs (but not easy to use) is exiftool by Phil Harvey http://www.sno.phy.queensu.ca/~phil/exiftool/ , which also works very well on MacOSX for a lot of file formats but maybe an overkill for your purpose.
I did this to investigate:
# create a black-to-white gradient and save as a BMP, then `identify` it to a file `unlim`
convert -size 256x256 gradient:black-white a.bmp
identify -verbose a.bmp > unlim
# create another black-to-white gradient but force 256 colours, then `identify` to a second file `256`
convert -size 256x256 gradient:black-white -colors 256 a.bmp
identify -verbose a.bmp > 256
# Now look at difference
opendiff unlim 256
And the difference is that the -colors 256 image has a palette in the header and has a Class:PseudoClass whereas the other has Class:Direct

Resources