Overlaying or merging multiple .ps files - overlay

I have used gmt to create several .ps files of x - y graphs with identical axes. I have several sets of data, each containing between 14 and 20 plots. Each plot is in a separate directory.
I would like to overlay every .ps within a dataset, in order to show correlation between the plots.
I know this is similar to the thread posted here:
overlay one pdf or ps file on top of another
but I don't have to deal with multiple pages.
I'm not a programmer, I'm a student! I would really appreciate a quick-ish way to stack them on top of each other to see an overall trend.
If not, I'm off to buy a stack of OHP films and find the nearest photocopier.... which would not look nearly as shiny.
All help is appreciated!

I've done something like this before, using GMT to produce two plots (of opposite sides of the Earth) to PS and overlaying them, one flipped 180 degrees and reflected (that is, depicting the Earth as a projective plane with each point equated with its antipode).
This was my code:
#!/bin/sh
GMT gmtset BASEMAP_FRAME_RGB +192/192/192
GMT gmtset BASEMAP_FRAME_RGB 0/0/0
GMT pscoast -JS-60/0/16 -R0/360/-90/90 -Di -A5000 -N1 -W -GP300/15:FLightRedB- -SWhite -P -K > mapa.ps
GMT pscoast -JS120/0/16 -R0/360/-90/90 -Bg30/g15 -Di -A5000 -N1 -W -GP300/15:FLightGreenB- -Sp1/50:F-B- -P -O > mapb.ps
sed -i 's/595 842/600 600/g' mapa.ps
sed -i 's/PSL/180 rotate -1 1 scale 0 -1890 translate \nPSL/' mapb.ps
cat mapa.ps mapb.ps > mapc.ps
ps2pdf mapc.ps
Commenting out the second sed line overlays them without flipping the second one. You can probably achieve what you want by tweaking this script and replacing the GMT commands with whatever you're using. The -O option used for the second plot sets overlay mode, which omits the PS code that triggers the creation of a new page. Then you can just cat them together.

Well, the Inkscape website says it can import PostScript. take that with a grain of salt, though- I haven't tried it myself.
Alternately, if you don't mind getting your hands a little dirty, PostScript is a fairly human-readable stack based programming language- I highly recommend A First Guide To PostScript. If you can figure out what chunk of the documents contains the plot you want, you ought to be able to copy and paste those together. This all depends heavily upon the quality and organization of code generated by GMT.
Your best bet is probably a vector graphics application like Inkscape (above) or Adobe Illustrator.

Related

FFMPEG Interpolated Video | First frame frozen without any interpolation to the second one

I've a small issue when generating interpolated videos from a short image sequence for a VQGAN+Clip Art Porject
The problem i've is just that the first frame stucks for a moment, then it jumps to the second one, the second one is also stuck for a moment but then it starts and works nicely. My biggest problem with it is the harsh transition from 1st to 2nd frame, the 2nd frame "start delay" is not that big an issue to me, but woul also be nice to get rid of for
Thats my command for generating the Video from an image sequence
ffmpeg -framerate 1 -i Upscaled\%d_out.png -vcodec h264_nvenc -pix_fmt yuv420p -strict -2 -vf minterpolate="mi_mode=mci:me=hexbs:me_mode=bidir:mc_mode=aobmc:vsbmc=1:mb_size=8:search_param=32:fps=30" InterpolatedVideo.mp4
You can see the result >> HERE <<
Now my question is if thats fixable by editing the command & if so, how?
I'd like to keep the first frame, but having it interpolate to the second frame.
I want to avoid to manually cut it afterwards, as i'd need to know the time to cut etc.
Thanks for any help in advance
Greetings from Vienna
Okay so what the problem was is the scene change detection aka. the scd parameter of the interpolation instruction. It's set to fdiff(frame difference) by default. Setting it to none with scd=none in the interpolation instruction gets rid of it
I also had to copy the 1st frame TWICE at the end to create a smooth loop. With only one, it entirely missed the last(copied first frame). I now copied it once morre at the end and it works now super smoothly. I guess the very last frame could be anything, as it misses it anyway

Why does PIL.Image.rotate() results in loss of quality despite `resample=Image.BICUBIC`

Per https://stackoverflow.com/a/17822099/1639359 using resample=PIL.Image.BICUBIC should retain quality through rotation. This question is follow up from my comment on the above answer that it is not working for me.
What version of Python and PIL do we have:
import sys
print(sys.version)
3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0]
import PIL
import PIL.Image
print(PIL.__version__)
print(PIL.Image.__version__)
6.2.1
6.2.1
Open our test image, and save it. Notice the loss of quality; saved file is much smaller than original:
img = PIL.Image.open('test_image.jpg')
holdexif = img.info['exif']
img.save('testsave.jpg',"jpeg",exif=holdexif)
%ls -l 'test_image.jpg'
%ls -l 'testsave.jpg'
-rwxrwxrwx 1 dino dino 1926859 Dec 24 21:28 test_image.jpg*
-rwxrwxrwx 1 dino dino 452343 Dec 27 13:16 testsave.jpg*
Per Determining JPG quality in Python (PIL) setting quality='keep' prevents the loss of quality on save:
img.save('testsave.jpg',"jpeg",exif=holdexif,quality='keep')
%ls -l 'test_image.jpg'
%ls -l 'testsave.jpg'
-rwxrwxrwx 1 dino dino 1926859 Dec 24 21:28 test_image.jpg*
-rwxrwxrwx 1 dino dino 1926911 Dec 27 13:16 testsave.jpg*
If we rotate the image, two things happen:
img.format disappears
quality is reduced significantly (even though we use resample=PIL.Image.BICUBIC)
print(img.format)
JPEG
rotated_img = img.rotate(-90,resample=PIL.Image.BICUBIC,expand=True)
print(img.format)
print(rotated_img.format)
JPEG
None
Saving the rotated file shows the loss of quality:
rotated_img.format="JPEG" # quality='keep' will raise exception if format != 'JPEG'
rotated_img.save('testsave.jpg',"jpeg",exif=holdexif,quality='keep')
%ls -l 'test_image.jpg'
%ls -l 'testsave.jpg'
-rwxrwxrwx 1 dino dino 1926859 Dec 24 21:28 test_image.jpg*
-rwxrwxrwx 1 dino dino 450997 Dec 27 13:16 testsave.jpg*
Questions:
1. What, if anything, am I doing wrong?
2. Why does img.format disappear on rotate? What else is disappearing?
3. And, just as an aside, is there another way to detect the loss of quality (I only know to save the file and see that it is much smaller).
After #MarkRansom 's comments, I would like to add some color to my question: Although I have been coding for many years, I only last week began playing with images. Without a doubt my knowledge of image processing is minimal at best, with significant gaps and misunderstandings about how things work.
That said, from a coding perspective, I would expect that a method on an object would do pretty much only what that method suggests, with no side effects. For example, I would expect rotate() only to rotate the image, and not clear out meta data at the same time. Even if, let's say for efficiency sake, the default behavior for the PIL package is to always drop the meta data, I would hope there would be an option (either global, or on a per-method basis) for something like preserve_metadata=True
Regarding "the only good way to judge quality" being "to look at the images themselves," I can certainly understand that being the case on an absolute basis. However on a relative basis, most notably when comparing the "same" image before and after some processing, it seems to me there could be ways to physically measure, or at least estimate, the difference in quality before and after the processing. (Of course, I don't yet know enough about images to know what the best method of doing that would be; thus part of the reason for my question). It also seems to me (at least from my beginner perspective) that very often people would want to do whatever processing that want to do with little or no loss of quality at the same time. Thanks for your patience and help filling in my knowledge gaps, and with the answers.
In general, any image rotation is going to result in a loss of image quality simply because the output requires an interpolation of the input for pixels that don't map 1:1 from input to output. For rotations of multiples of 90 degrees, it's possible to get a 1:1 mapping and do a lossless rotation. It's not clear if PIL/Pillow is smart enough to do that, but it might. Your example rotates by -90 degrees so you could luck out.
The metadata is being lost because rotate generates a new image, it doesn't modify the existing one. It's not easy to determine which metadata might be relevant for the new image, so the safest course of action is to simply not copy any of it. As you've discovered, it's possible to manually copy anything you think is important. I don't think there's an option to automatically copy anything.
As noted in the comments, using file size as a judge of image quality is a very poor metric. A smaller size is suggestive of poorer quality, but it doesn't have to be so; the whole premise of JPEG compression is that some image degradations simply won't be visible in normal viewing. A visual comparison is the ultimate test. If you must have an automated comparison there are methods to do so, but I don't think any have emerged as the undisputed best way to compare.
You rotated the image, which creates a new generic image. There is no 'keep' in this instance. When saving to JPEG, default quality is 75, high quality is 95.
Need to copy quality, perhaps tables, and metadata to the new image, just as you are doing with the Exif.

exporting svg image from matlab surface plot

I need some to produce some publication-quality figures. I first export the figures from matlab in .svg format, and then I do some post-processing in inkscape. I am no problem with figures generated using plot or scatter, but when I export figures generated using surf (in view(2)), I run into problems. If I use plot or scatter, I am able to ungroup and process various parts like the title, axes, scattered points, lines, etc. in inkscape. For surf, however, matlab just exports one single figures with all various parts grouped into one single unit. I can't separate individual part, and when I zoom very close I can actually see the bitmap resolution for the axes and titles (if I use plot, the titles and axes have 'infinite' resolution when I zoom very close). I am fine with the surface plot having finite resolution, but I need to at least be able to process the axes and titles (which I currently cannot do). What should I do so that I can 'separate' the title and axes from the main plot, just like figures generated from plot and scatter?
I stumbled across this question, since I encountered the same problem.
As mentioned by #vindarmagnus, it is possible to use tikz and get rather nice results. However, tikz experiences problems with large data sets in my experience as present when using surf etc..
Solution, that worked for me:
Change the renderer to painters and the exported .svg file will retain its vectorgraphic properties when opened e.g. in inkscape:
figure('Renderer','Painters');
I used to use Inkscape for my scientific publications as well, but I found that a lot of the time you can get better results with pgfplots in latex, together with the matlab2tikz matlabscript. There’s a ton of resources about this online, but here’s how my workflow would look adopted to your surf situation. I have macOSX with latex, matlab and matlab2tikz installed. Will work with little to no modifications on linux.
In Matlab:
surf(peaks(25))
matlab2tikz('plot.tikz’)
Then I have the following bash-script (just a script in the same folder as the image, which is executed by mere double-click). (Needs to be chmod-ed as an executable for that).
#!/bin/bash
cd ~/Desktop
rm *.eps
cat > plot.tex << EOF
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{max space between ticks=50}
\pgfplotsset{scaled ticks = false}
\pgfplotsset{compat=1.6}
\pgfplotsset{xticklabel style={/pgf/number format/fixed}}
\pgfplotsset{yticklabel style={/pgf/number format/fixed}}
\begin{document}
\input{plot.tikz}
\end{document}
EOF
pdflatex plot.tex
pdf2ps plot.pdf
ps2eps plot.ps
Note that the row cd ~/Desktop above should be changed as to reflect which folder the script is supposed to be run from (a bit crappy, but needed since Finder doesn’t properly pass along the folder from a program is executed, afaik).
This yields high-quality images in eps or pdf or what you like, with a ton of settings for axes and ticks etc. And it all uses native latex fonts.
Edit:
Recently I’ve begun to use patch() in matlab and then export it to tikz in the same manner as above, with great results. That’s another suggestion!
You can use also:
set(gcf,'Renderer','Painters')

Libreoffice Draw Export Resolution makes no sense

I am attempting to make a very simple label using Libreoffice Draw v 4.0.2.2. The label has not much more to it than regularly spaced lines of centered text
This image will be printed, and I have a fixed size/ppi requirement to ensure appropriate print quality.
I set the page size to my specs, and layout the text as I desire. The print shop takes several image formats including .tiff and .png. When I export the image, a dialog pops up that asks for the image size/ resolution. The given ppi is very low (~40) and I require a minimum of 180ppi. When I enter this, the image size adjusts itself and results in an image that is far too small.
The only solution that appears to be viable is to explode the page size and the drawing text size so it gets shrunk upon export. This is a very imprecise and illogical feature (bug?) of the program that I really wish is a result of my ignorance.
I found a thread in the mailing list which describes this issue exactly. The only answer that is given is essentially "yes, this is ridiculous and doesn't help anybody".
Can anyone give some advice to this? Or at least shed some light on who might need this "feature"?
There is something off about the Export tool of LibreOffice in general. It has been years since it is broken. Taking a screenshot is an alternative, but obviously you cannot control the resolution.
So, a better work around is exporting to SVG, and then convert the SVG to PNG with Inkscape. Once downloaded, convert the file with the following command:
inkscape -z -e out.png -w 1024 in.svg
If you are in Windows (x64), you will need to indicate the full path:
"C:/Program Files/Inkscape/inkscape.exe" -z -e out.png -w 1024 in.svg
If you install the 32 bit version, this should work:
"C:\Program Files (x86)/Inkscape/inkscape.exe" -z -e out.png -w 1024 in.svg
This can be done from inside Libre Office, there is no need to use any external tool. The Export dialog is very confusing, yes; you have to realize that both size and resolution can be set independently.
Select File -> Export -> choose the desired format. The export dialog should appear.
TAKE NOTE of Width and Height. Set the desired resolution; notice how Width and Height change (?). Don't worry, restore Width and Height to your saved values. And that's it. You get a high resolution image with the desired size and DPI.
Libre Draw (the one I'm using anyway) is a vector drawing app - have you asked the print shop if they can use vector formats like eps, pdf? Most should be able to in my experience. Then resolution becomes irrelevant.
-Terry

Line detection using PIL

Given an image consisting of black lines (a few pixels wide) on white background, what is a good way to find the coordinates along the the lines, say for every 10th pixel or so? I am considering using PIL for the task, but other python or java-based libraries would also be OK.
Ideally the coordinates would point to the middle of the line, but as the lines are narrow, it's enough that they point somewhere inside the line.
A very short line or a point should be identified with at least one coordinate.
Usually, Hough transformation is used to find lines. It gives you the parameters describing the line (which can be transformed easily between different representations), and you can sample this function to get your sample points. See http://en.wikipedia.org/wiki/Hough_transform and https://stackoverflow.com/questions/tagged/hough-transform+python
I only found this http://coding-experiments.blogspot.co.at/2011/05/ellipse-detection-in-image-by-using.html implementation in python, which actually searches for ellipses.