($VersionNumber < 6) Cropping an exported image in Mathematica - graphics

This is an animation I made using Mathematica. As can be seen by highlighting the image, the margins at both the left and right sides are too wide. I don't want to have to submit the image to another program just for the cropping, so what do I do to eliminate the whitespace?
Looking at the documentation, ImageMargins and ImageRegion would have been good except that they only apply to the front end. So, what do I do?

I think you will possible find useful these two articles (although the first is for Mathematica 6 and the second is for v.7):
Exporting Pixel-Perfect Graphics in Mathematica
and
Pixel-perfect Graphics, Revisited.

Try using the PlotRegion option.
Here is an example:
Plot[Sin[x], {x, 0, 10},
Axes -> False, Frame -> True,
PlotRegion -> {{0.1, 0.9}, {0.1, 0.9}}]
I tested this in v8 after doing <<Version5`Graphics`

First, I would try the PlotRangePadding option to your Plot function. If the expression is already rasterized, you can try something like this:
imagelist /. Raster[a_, rest___]:> Raster[Take[#, {10, -10}]& /# a, rest]
This should chop 10 pixels off either side. The image processing tools in V7 are quite nice and if you are able, I think you'd find the upgrade a very worthwhile investment.

Related

How can I get the color of a pixel on screen with Node.js or C?

I am trying to get the color of a pixel on my screen using node.js. I want it to be returned in RGB format, e.g. (255, 0, 0). My current solution is to use screenshot-desktop to screenshot my entire screen in JPG format, decode it to get the raw pixel data, and get the color of a given pixel. However, this lags out my entire computer for 1-2 seconds as it is taking the screenshot. This is unusable as I would like to do this multiple times per second. So my question is: How can I get the color of a given pixel on the screen, without taking a full screenshot?
I am using Linux with X11. There is an X11 library for node.js, so I asssume I should use that to get the pixel color, I'm just not sure how. If you could show me how to do it in C then I can easily use node.js to do the same thing.
Thanks!
Oh my gosh I just figured it out after posting this. I was using robotjs for reading the mouse position and I totally forgot it can do screen stuff too! So, the solution would be to do
var robot = require('robotjs');
var color = robot.getPixelColor(x, y);
X11 solution using x11 node library ( I am the author ):
query windows tree with QueryTree starting at the root window
get every child geometry using GetGeometry request
if your point is not inside any child, use current window id and get 1x1 pixmap from the current image: GetImage(format, currentWindow, x, y, 1, 1, planeMask) ( 2 for format and 0xffffffff for plane mask should work ). Make sure you calculate relative x y position as you travers windows tree.
if child window covers your point query children for that window and repeat again. Note that QueryTree returns windows in bottom to top stacking order so make sure you pick last one covering your point
Once you have 1x1 pixmap from the topmost window under your point - the buffer should contain only color bytes for your image, RGB order and bit mask might depend on red_mask, green_mask, blue_mask from display.screen[0].depths[visual].
If you cache "topmost window" between requests and only start from root when no match anymore the above solution might be much more performant then the one using robotjs ( although much more low level and complicated ) Good luck!

How to code circles around text in Mathjax

The following image is from an exercise in Chiswell and Hodges Mathematical Logic, page 21:
I would like to display something similar when I post an answer on Mathematics Stack Exchange, but I don't know how to make the circles with the numbers inside nor the forward slashes through the letters in Mathjax. I think I can handle the fractions with "\frac" as well as the rest of it.
I've looked for examples from other posts to copy, but people seem to replace the circle with parenthesis as an alternative.
Would someone be able to show me how or what software I should use to get this effect?
There are a number of possible ways to get a circle around the one. Here are three:
Use the enclose extension with the circle notation:
\require{enclose}
{\scriptstyle \enclose{circle}{\kern .06em 1\kern .06em}}
You only need to include the \require{enclose} once on the page before your first usage of \enclose. The \kern commands are to make the circle be round rather than oval, since the size of the one is taller than it is wide.
Use \rlap to place the 1 over top of a \bigcirc:
{scriptstyle \rlap{\kern .18em 1}\raise.04em{\bigcirc}}}
we also raise the big circle slightly to get the placement better.
Use the \unicode{} command to obtain the U+2460 character, which is "circled digit one":
{\textstyle\unicode{x2460}}
You can use the cancel package to get \cancel, which produces an diagonal upward slash over its argument, and use a superscript to put the circled 1 in place:
{scriptstyle\cancel{\psi}^{\raise.2em{\enclose{circle}{\kern .06em 1\kern .06em}}}}
Putting this all together with your fractions, you can do something like the following horrible hack:
\require{enclose}\require{cancel}
\frac{
\lower.3em{\scriptstyle\cancel{\psi}\raise.6em{\enclose{circle}{\kern .06em 1\kern .06em}}}
\kern 2.6em
\frac{(\psi\wedge\phi)}{\phi}
{\scriptstyle (\wedge\rm E)}
\kern -2.5em
}{
\kern -.7em
{\scriptstyle\enclose{circle}{\kern .06em 1\kern .06em}}
\frac{(\psi\wedge\phi)}{(\psi\rightarrow(\psi\wedge\phi))}
{\scriptstyle(\rightarrow\rm I)}
\kern -1.7em
}\ {\scriptstyle (\wedge\rm I).}
This includes a lot of spacing adjustments by hand to get the fraction lines to be the right length. It would be painful to do this for very many of these.
Here is the result:

Can I create a Calligraphy look with SVG?

is it possible to create a stroke with a dynamic width with SVG? I want to achieve a Calligraphy look like here, here or here.
Is this even possible? It seems customization of strokes in SVG is fairly limited. Even gradients in strokes seem to be non-trivial (see here).
There is a proposal to add into SVG standard a mechanism, that does exactly what you want:
http://www.w3.org/Graphics/SVG/WG/wiki/Proposals/Variable_width_stroke
http://lists.w3.org/Archives/Public/www-svg/2013May/0041.html
There's even an example implementation available here:
https://rawgit.com/birtles/curvy/master/index.html
It is, however, by no means official and we cannot be even sure it'll ever be.
Until then you'll need to stick to Bezier curves and object filling:
You can also use calligraphic fonts, for example - Tangerine available on Google CDN:
This approach requires less work since you don't need to draw everything from scratch, but then again, using third party fonts leaves you with little control over the final result.
You can't dynamically adjust the stroke of a path element. However you could draw a path, use a fill color on it instead of stroke, then double back upon the letters at a slight distance away from the original line.
Also, if you are using the SVG on the web then you can use css fonts on text elements. There are some pretty good cursive fonts that you can use for free... just check google web fonts.

Edit image, using openGL

I have been doing some searching the last couple of days and I have been curious how to do this. I have a UIImagePickerController.
So I want to add a effect like black and white, sepia, etc. I am creating a custom UIImagePickerVController and I am curious. Can this be done with OpenGL ES? If so, how?
This is possible through the use of pixel shaders using OpenGL-ES 2.0. You could also write an Objective-c++ routine that gets all the pixels of your image into an array then applies a custom algorithm to modify the color of the image.
Edit:
Here are some links that might help get you started.
http://www.sunsetlakesoftware.com/2010/10/22/gpu-accelerated-video-processing-mac-and-ios
http://www.dreamincode.net/forums/topic/76816-image-processing-tutorial/
http://www.efg2.com/Lab/Library/ImageProcessing/Algorithms.htm

Alternatives to using text() to adding text to a plot

This may be a naive question, but I was wondering if there's a better way than using text() to adding text to a plot. Note, I'm also using layout() as well. Specifically, I have a section of a plot where I would like to add some text with headings followed by regular text.
text() is fine it seems for simple annotations, but to get the spacing right for several lines of text seems to require a lot of manual manipulation of the x and y and cex parameters. Any suggestions?
Here are some alternative options to consider:
- the gplots package has a textplot function to add some text output in a base graphics plot.
- plotrix has a function addtable2plot
- for grid graphics grid.text() is available and in gridExtra there is a function grid.table() (see, e.g., R-Wiki)
If you're using base graphics, then text() is probably your best bet, and fiddling with coordinates etc is part of the game. If you want to learn a new framework, the lattice package is a reworking of the basic approach to plotting in R. It be installed by default so help(package='lattice') will get you started.
Here's a pretty good guide (pdf) to graphics in general in R, with a substantial section on lattice:
download

Resources