I am using graphviz twopi to generate a png file. I have many dot files but only three which cannot be converted to png. Below is one simplified example which cannot be converted:
digraph G{
overlap = false;
splines = true;
root = "a";
"a" [label ="ATCC 12633"];
"b" [label = "R M Egan",fontsize=25];
"a" -> "b" [label = "paper:1",penwidth = 4,color = black ,len=2];
"c" [fontsize=25, label = "ATCC 8014"];
"b" -> "c" [label = "paper:1"];
}
I use -v to see the details, which are:
mongodb#mongodb:/home/wuchang/newStore/allYear$ sudo twopi ATCC_12633_1977.dot -Tpng -o 77.png -v
twopi - graphviz version 2.26.3 (20100126.1600)
Activated plugin library: libgvplugin_pango.so.6
Using textlayout: textlayout:cairo
Activated plugin library: libgvplugin_neato_layout.so.6
Using layout: twopi:neato_layout
Using render: cairo:cairo
Using device: png:cairo:cairo
The plugin configuration file:
/usr/lib/graphviz/config6
was successfully loaded.
render : cairo dot fig gd map ps svg tk vml vrml xdot
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : canon cmap cmapx cmapx_np dot eps fig gd gd2 gif gv imap imap_np ismap jpe jpeg jpg pdf plain plain-ext png ps ps2 svg svgz tk vml vmlz vrml wbmp x11 xdot xlib
loadimage : (lib) eps gd gd2 gif jpe jpeg jpg png ps svg
fontname: "Times-Roman" resolved to: (ps:pango Times Roman,) (PangoCairoFcFont) "DejaVu Sans 14"
root = a
Rank separation = 0.000 1.000 2.000
Adjusting G using Voronoi
Node separation: add=1 (4.000000,4.000000)
I doubt it is just a bug in graphviz. My graphviz version is 2.26.3, my OS is Ubuntu 12.04.3 LTS.
Compared with a successfully-converted dot file whose convertion output is:
mongodb#mongodb:/home/wuchang/newStore/allYear$ sudo twopi ATCC_12633_1988.dot -Tpng -o 88.png -v
twopi - graphviz version 2.26.3 (20100126.1600)
Activated plugin library: libgvplugin_pango.so.6
Using textlayout: textlayout:cairo
Activated plugin library: libgvplugin_neato_layout.so.6
Using layout: twopi:neato_layout
Using render: cairo:cairo
Using device: png:cairo:cairo
The plugin configuration file:
/usr/lib/graphviz/config6
was successfully loaded.
render : cairo dot fig gd map ps svg tk vml vrml xdot
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : canon cmap cmapx cmapx_np dot eps fig gd gd2 gif gv imap imap_np ismap jpe jpeg jpg pdf plain plain-ext png ps ps2 svg svgz tk vml vmlz vrml wbmp x11 xdot xlib
loadimage : (lib) eps gd gd2 gif jpe jpeg jpg png ps svg
fontname: "Times New Roman Bold" resolved to: (PangoCairoFcFont) "DejaVu Sans Bold 30"
fontname: "Times-Roman" resolved to: (ps:pango Times Roman,) (PangoCairoFcFont) "DejaVu Sans 24.9990234375"
root = -290487096
Rank separation = 0.000 1.000 2.000
Adjusting G using Voronoi
Node separation: add=1 (4.000000,4.000000)
Number of iterations = 5
Number of increases = 3
Edge separation: add=1 (3.200000,3.200000)
Creating edges using splines
Using render: cairo:cairo
Using device: png:cairo:cairo
twopi: allocating a 1477K cairo image surface (907 x 417 pixels)
I tried many many modifications such as:
If I remove overlap=false, it can generate the png file but the
generated graph's node is overlapped, which doesn't meet my
requirement.
When I remove fontsize = 23 for node "c", it also
can generate the png file, but the png file is completely
wrong.
I'd suggest updating to a newer version of Graphviz. There has been a lot of development in the last four years. Because your verbose output ends before the number of iterations is displayed, I strongly suspect it's a bug (maybe an infinite loop) the version of Graphviz you're using.
Using 2.36.0 under OS X, your file gives me this (which is obviously not what you want):
If I comment out the line root = "a"; I get this:
Related
I tried using the following line:
gdal_translate -of jpeg -a_nodata 0 -b 1 -b 2 -b 3 c:\myfolder\mytif.tif c:\myfolder\myNewtif.jpg
This produces the image with wanted specs, but turns the background to black (transparency?), eventhough the original has white. Can I accomplish a white background with just gdal_translate?
File dump of a file with mask:
https://filebin.net/f15v63to2x3cc4z0
File dump of a file with no a mask: https://filebin.net/kc940hqotcoeny0w
gdalinfo output of a Tif that produces white background as expected:
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 4799, 3196
Metadata:
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_XRESOLUTION=300
TIFFTAG_YRESOLUTION=300
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 3196.0)
Upper Right ( 4799.0, 0.0)
Lower Right ( 4799.0, 3196.0)
Center ( 2399.5, 1598.0)
Band 1 Block=4799x1 Type=Byte, ColorInterp=Red
Band 2 Block=4799x1 Type=Byte, ColorInterp=Green
Band 3 Block=4799x1 Type=Byte, ColorInterp=Blue
Tif that produces black background:
Warning 1: TIFFFetchNormalTag:Incompatible type for "RichTIFFIPTC"; tag ignored
Driver: GTiff/GeoTIFF
Files: 100011_1.tif
Size is 1640, 2401
Metadata:
TIFFTAG_DATETIME=2020:01:13 12:29:55
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_SOFTWARE=Adobe Photoshop 21.0 (Windows)
TIFFTAG_XRESOLUTION=300
TIFFTAG_YRESOLUTION=300
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 2401.0)
Upper Right ( 1640.0, 0.0)
Lower Right ( 1640.0, 2401.0)
Center ( 820.0, 1200.5)
Band 1 Block=1640x39 Type=Byte, ColorInterp=Red
Mask Flags: PER_DATASET ALPHA
Band 2 Block=1640x39 Type=Byte, ColorInterp=Green
Mask Flags: PER_DATASET ALPHA
Band 3 Block=1640x39 Type=Byte, ColorInterp=Blue
Mask Flags: PER_DATASET ALPHA
Band 4 Block=1640x39 Type=Byte, ColorInterp=Alpha
Also of the following images that have black background after translate, gdal produces this warning "Warning 1: TIFFFetchNormalTag: Incompatible type for "RichTIFFIPTC"; tag ignored"
The file that you have shared on filebin contains an "alpha" mask, as you can see in the output of gdalinfo. The mask of this file says that the background is masked, while the rest of the image is not.
If you display the tiff with the default Ubuntu viewer, for example, you can see that the background pixels are masked out (they appear as a checker board)
If you inspect the raster data, you also see that the underlying pixels from the background are black, not white. That is why gdal_translate generates a jpeg with black pixels in the background, it is because they really are black (but masked out) in the original tiff file.
If you absolutely want the background to be white, you can do so with a few lines of Python using the rasterio library for example, by explicitly setting the masked pixels to white:
import rasterio
with rasterio.open("101679_1.tif") as src:
arr = src.read(masked=True)
# Convert all masked values to white
arr[arr.mask] = 255
# Write to jpeg file
profile = src.profile
profile["count"] = 3
profile["driver"] = "jpeg"
with rasterio.open("test.jpeg", "w", **profile) as dst:
dst.write(arr[:3])
This should give the following jpeg file:
The code snippet I have included above will also work on TIF files which already have a white background, because the arr[arr.mask] = 255 line will not do anything if the file contains no mask.
To process a directory full of .tif files, you can do:
from glob import glob
import rasterio
for tif in glob("*.tif"):
with rasterio.open(tif) as src:
arr = src.read(masked=True)
# Convert all masked values to white
arr[arr.mask] = 255
# Write to jpeg file
profile = src.profile
profile["count"] = 3
profile["driver"] = "jpeg"
with rasterio.open(tif.replace(".tif", ".jpeg"), "w", **profile) as dst:
dst.write(arr[:3])
My eventual goal is to decode CR2 images from multiple cameras for display in a desktop gui.
Using the LibRaw image decoding library, I've used the sample project to attempt to decode a CR2 image into a .TIFF file.
The original file as a jpg thumbnail is as follows:
Image 1
And the original CR2 after decoding and saving into a .TIFF is as follows:
Image 2
As you can see, the outcome is slightly brighter and yellowish.
The sample project was contains the following parameters for decoding images:
"-c float-num Set adjust maximum threshold (default 0.75)\n"
"-v Verbose: print progress messages (repeated -v will add verbosity)\n"
"-w Use camera white balance, if possible\n"
"-a Average the whole image for white balance\n"
"-A <x y w h> Average a grey box for white balance\n"
"-r <r g b g> Set custom white balance\n"
"+M/-M Use/don't use an embedded color matrix\n"
"-C <r b> Correct chromatic aberration\n"
"-P <file> Fix the dead pixels listed in this file\n"
"-K <file> Subtract dark frame (16-bit raw PGM)\n"
"-k <num> Set the darkness level\n"
"-S <num> Set the saturation level\n"
"-n <num> Set threshold for wavelet denoising\n"
"-H [0-9] Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild)\n"
"-t [0-7] Flip image (0=none, 3=180, 5=90CCW, 6=90CW)\n"
"-o [0-5] Output colorspace (raw,sRGB,Adobe,Wide,ProPhoto,XYZ)\n"
#ifndef NO_LCMS
"-o file Output ICC profile\n"
"-p file Camera input profile (use \'embed\' for embedded profile)\n"
#endif
"-j Don't stretch or rotate raw pixels\n"
"-W Don't automatically brighten the image\n"
"-b <num> Adjust brightness (default = 1.0)\n"
"-q N Set the interpolation quality:\n"
" 0 - linear, 1 - VNG, 2 - PPG, 3 - AHD, 4 - DCB\n"
#ifdef LIBRAW_DEMOSAIC_PACK_GPL2
" 5 - modified AHD,6 - AFD (5pass), 7 - VCD, 8 - VCD+AHD, 9 - LMMSE\n"
#endif
#ifdef LIBRAW_DEMOSAIC_PACK_GPL3
" 10-AMaZE\n"
#endif
"-h Half-size color image (twice as fast as \"-q 0\")\n"
"-f Interpolate RGGB as four colors\n"
"-m <num> Apply a 3x3 median filter to R-G and B-G\n"
"-s [0..N-1] Select one raw image from input file\n"
"-4 Linear 16-bit, same as \"-6 -W -g 1 1\n"
"-6 Write 16-bit linear instead of 8-bit with gamma\n"
"-g pow ts Set gamma curve to gamma pow and toe slope ts (default = 2.222 4.5)\n"
"-T Write TIFF instead of PPM\n"
"-G Use green_matching() filter\n"
"-B <x y w h> use cropbox\n"
"-F Use FILE I/O instead of streambuf API\n"
"-timing Detailed timing report\n"
"-fbdd N 0 - disable FBDD noise reduction (default), 1 - light FBDD, 2 - full\n"
"-dcbi N Number of extra DCD iterations (default - 0)\n"
"-dcbe DCB color enhance\n"
#ifdef LIBRAW_DEMOSAIC_PACK_GPL2
"-eeci EECI refine for mixed VCD/AHD (q=8)\n"
"-esmed N Number of edge-sensitive median filter passes (only if q=8)\n"
#endif
#ifdef LIBRAW_DEMOSAIC_PACK_GPL3
//"-amazeca Use AMaZE chromatic aberrations refine (only if q=10)\n"
"-acae <r b>Use chromatic aberrations correction\n" //modifJD
"-aline <l> reduction of line noise\n"
"-aclean <l c> clean CFA\n"
"-agreen <g> equilibrate green\n"
#endif
"-aexpo <e p> exposure correction\n"
// WF
"-dbnd <r g b g> debanding\n"
#ifndef WIN32
"-mmap Use mmap()-ed buffer instead of plain FILE I/O\n"
#endif
"-mem Use memory buffer instead of FILE I/O\n"
"-disars Do not use RawSpeed library\n"
"-disinterp Do not run interpolation step\n"
"-dsrawrgb1 Disable YCbCr to RGB conversion for sRAW (Cb/Cr interpolation enabled)\n"
"-dsrawrgb2 Disable YCbCr to RGB conversion for sRAW (Cb/Cr interpolation disabled)\n"
"-disadcf Do not use dcraw Foveon code either if compiled with demosaic-pack-GPL2\n"
I've tried various options to replicate the image in the thumbnail, such as white balancing (-w), interpolation quality (-q N), and embedded color matrix (+M). When I used white balancing, it removed the yellowish tint but produced a bright image. I then went on to disable automatic brightening (-W) and it produced a non-yellow image but much darker than the thumbnail.
What image decoding parameters will help me to decode the CR2 into the a high-quality image that looks like the thumbnail (in terms of color, brightness, etc.)?
Problem solved.
While I don't have the specifics just yet, my senior said windows didn't support the original formatting option, and he also moved memory row-by-by.
I would like to draw Arabic text into bitmap (bmp or png) with command line interface.
I have tried imagemagick and RMagick, but I have problem with RTL language issue. all my rendering are left to right. And google is not helping.
require:
./render "لوحة المفاتيح" out.png
would give a bitmap:
لوحة المفاتيح
Anyone can give me some successful results?
Anyone can give me some successful results?
I can. I use convert from ImageMagick:
echo لوحة المفاتيح > text.txt && \
convert -size 300x200 \
-background white \
-fill black \
-font /usr/share/fonts/truetype/droid/DroidNaskh-Regular.ttf \
-pointsize 24 \
-gravity Center \
label:#text.txt \
text.png
This is the result:
Some notes:
You need to use a font which defines the used characters (in your case an arabic font)
Always use a temporary file with the text inside instead of provide the text directly from the command line: it would lead to weird results
UPDATE I didn't notice the RTL part of the question; I think I got better results using pango (reference):
# On Ubuntu
sudo apt-get install libpango1.0-dev
echo -n لوحة المفاتيح > text.txt
pango-view text.txt --no-display --output text.png
Result:
For Arabic typography, you might want to use Inkscape 0.9 as follows (Window7 cmd):
inkscape "ar.svg" --export-png="C:\Users\Path\TO\output\arabicthabit.png" --export-dpi="900,900" --export-background="rgb(100%,100%,100%)"
Where ar.svg is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="400"
height="100"
version="1.1">
<text
xml:space="preserve"
style="font-size:30px;font-style:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:'Droid Arabic Naskh';font-weight:bold;"
x="10" y="90"
><tspan>لغةٌ عربيّةٌ</tspan>
</text>
</svg>
You can replace the font-family:'Droid Arabic Naskh' by any font in your system.
Also you can change the output format as stated in the man pages of Inkscape. Moreover, you can start in Inkscape GUI and save the SVG and change what you want in the SVG XML in any scripting language.
Inkscape 0.48 returned buggy Arabic typography.
As for ImageMagick 6.8.9-7, I used Python +Wand(Python Lib)+arabic_reshaper(Python Lib)+bidi.algorithme(Python Lib) to generate correct Arabic typography in images:
from wand.image import Image as wImage
from wand.display import display as wdiplay
from wand.drawing import Drawing
from wand.color import Color
import arabic_reshaper
from bidi.algorithm import get_display
reshaped_text = arabic_reshaper.reshape(u'لغةٌ عربيّة')
artext = get_display(reshaped_text)
fonts = ['C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\DroidNaskh-Bold.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit-Bold-Oblique.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit-Bold.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit-Oblique.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\majalla.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\majallab.ttf',
]
draw = Drawing()
img = wImage(width=1200,height=(len(fonts)+2)*60,background=Color('#ffffff'))
#draw.fill_color(Color('#000000'))
draw.text_alignment = 'right';
draw.text_antialias = True
draw.text_encoding = 'utf-8'
#draw.text_interline_spacing = 1
#draw.text_interword_spacing = 15.0
draw.text_kerning = 0.0
for i in range(len(fonts)):
font = fonts[i]
draw.font = font
draw.font_size = 40
draw.text(img.width / 2, 40+(i*60),artext)
print draw.get_font_metrics(img,artext)
draw(img)
draw.text(img.width / 2, 40+((i+1)*60),u'ناصر test')
draw(img)
img.save(filename='C:\\PATH\\OUTPUT\\arabictest.png'.format(r))
wdiplay(img)
I read the section OTHER OUTPUT FORMATS of Plotchart documentation, but still can't figure out how to do it.
I want to:
Save canvas as image without displaying it. So I can run it in batch mode.
Save in other format. (ex: jpeg, png...)
A brief example is appreciated.
I didn't try this solution, but the man page you linked describes a saveplot command to store the plot into a Postscript (or other image format) file.
Once you created your plot widget, you can do something like
.plot saveplot filename.ps -plotregion bbox
where the -plotregion bbox says to save all the plot and not just the visible part (-plotregion window, which is the default).
I found Img library is capable to converts Postscript into various formats, and a quick and dirty way do not display the canvas is to run exit immediately.
Here is an example:
package require Plotchart
package require Img
canvas .c -background white -width 400 -height 200
pack .c -fill both
set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
foreach {x y} {0.0 32.0 10.0 50.0 25.0 60.0 78.0 11.0 } {
$s plot series1 $x $y
}
$s title "Data series"
set file "test.ps"
$s saveplot $file
set root [file rootname $file]
set image [image create photo -file $file]
foreach {f suffix} {JPEG jpg GIF gif PNG png} {
$image write $root.$suffix -format $f
}
exit
Good day.
How to impose white_rectangle.jpg on logo.jpg in the image below
using Imagemagic.
And a bonus question: what's Ruby's method can make the task.
def (path_to_image)
# impose white_rectangle.jpg on logo
end
This can easily be accomplished using RMagick:
require 'RMagick'
logo = Magick::Image.read("logo.jpg").first
rect = Magick::Image.read("white_rectangle.jpg").first
result = logo.composite(rect, x, y, Magick::CopyCompositeOp)
result.write "result.jpg"
An alternative is to just draw a white rectangle without using a composite image:
image = Magick::Image.read("logo.jpg").first
gc = Magick::Draw.new
gc.stroke = 'white'
gc.fill = 'white'
gc.rectangle x_start, y_start, x_end, y_end
gc.draw(image)
image.write "result.jpg"
Using ImageMagick command line tools, you can overlay one image with another like this:
$ composite white_rectangle.jpg logo.jpg -geometry +x+y result.jpg