Map image into matrix in R to 3d Print - r

We have an image like this:
Where I have a skull, and the raw counts of how many bones were broken in each area of the skull.
I also have a 3d printer and can make things like this:
Which was made in R using a matrix and the r2stl package.
What I want to do is map the x's and y's of that skull into certain locations of a matrix so that I could add the raw counts to those cells and 3d print that skull in a way where each portion of the skull would be higher based on how many fractures were in that location. Thoughts? It didn't seem like an example where an example dataset would be useful, I apologize if I should have included that.

Related

How can I generate heatmaps from specific sections of data using GnuPlot? ('splot', 'every', 'using' incompatibilites etc.)

I am attempting to generate heatmaps from a data file I've been generating. I could re-format the data however I like, but for the time being, let's say it's a list of 16 numbers that I'd like put into a 4x4 heatmap. However, I have many sets of these 16 numbers sequentially in the same file, and hope to eventually animate them together (something I am more comfortable with, and will come later)
However, for the time being, I cannot find a way to get GnuPlot to select only certain sections of the data file while still plotting properly. A loose example of what I would've thought it WOULD look like:
plot "SortedData.txt" every ::0::15 w image
or:
splot "SortedData.txt" every ::0::15
Both give me errors and fail to render. I could label the data values with an x-y coordinate if needed, but the task is fairly repetitive: I just want the first 16 points mapped, and then the ability to iterate once and have the next 16 points mapped on their own, etc. Stripping the data file to just the first 16 points and removing the 'every' command confirms that it can plot, but trying to specify even just the first 16 manually messes it up.
Can anyone point me in the right direction? The "every" command has been fairly nebulous and seems largely incompatible with images / 3-D data. Also, I am running on Windows, so piping in linux commands is something I'd like to avoid.
Thanks!
edit: Here is 4 example frames of the data. Reformatting it to, say, present as a matrix or label with pixel addresses are all something I can do if needed.
0.000000 -49.314654 -44.425234 -46.613870 -48.494232 -46.884806 -46.553071 -46.555624 -43.755972 -47.817691 -42.481637 -46.819782 -44.347586 -49.487077 -47.291832 -45.140636 -47.945934
0.839906 -49.325396 -44.425493 -46.613214 -48.501283 -46.887236 -46.550858 -46.555285 -43.752786 -47.814706 -42.453793 -46.814333 -44.329492 -49.493501 -47.289394 -45.133555 -47.944045
1.679721 -49.336151 -44.425787 -46.612573 -48.508348 -46.889684 -46.548645 -46.554958 -43.749626 -47.811707 -42.425757 -46.808866 -44.311344 -49.499930 -47.286951 -45.126476 -47.942155
2.519466 -49.346920 -44.426117 -46.611946 -48.515427 -46.892152 -46.546431 -46.554641 -43.746492 -47.808695 -42.397525 -46.803382 -44.293140 -49.506365 -47.284501 -45.119398 -47.940264
It seems that each line in your data file has 17 elements. I assume that the first column is not part of your image data. I would format the remaining 16 values as a 4x4 matrix, with each frame separated by two blank lines:
-49.314654 -44.425234 -46.613870 -48.494232
-46.884806 -46.553071 -46.555624 -43.755972
-47.817691 -42.481637 -46.819782 -44.347586
-49.487077 -47.291832 -45.140636 -47.945934
-49.325396 -44.425493 -46.613214 -48.501283
-46.887236 -46.550858 -46.555285 -43.752786
-47.814706 -42.453793 -46.814333 -44.329492
-49.493501 -47.289394 -45.133555 -47.944045
-49.336151 -44.425787 -46.612573 -48.508348
-46.889684 -46.548645 -46.554958 -43.749626
-47.811707 -42.425757 -46.808866 -44.311344
-49.499930 -47.286951 -45.126476 -47.942155
-49.346920 -44.426117 -46.611946 -48.515427
-46.892152 -46.546431 -46.554641 -43.746492
-47.808695 -42.397525 -46.803382 -44.293140
-49.506365 -47.284501 -45.119398 -47.940264
You can then visualize each frame with the command
plot "data.dat" index FRAME matrix w image
where FRAME is 0, 1, 2 or 3.

Sort Extracted Data Based On Image Region

I have analysed tree core images through the raster package in an attempt to perform image analysis. In the image:
http://dx.doi.org/10.6084/m9.figshare.1555854
You can see the measured "vessels" (black and numbered) and also annual lines (red) which have been drawn using the locator function and represent each year of growth of the tree core.
By generating a list of the maximum y coordinates of each annual line I have been able to sort the vessels into years for this image. Which is what I am looking for. However, it has occurred to me that in reality things can get a little more difficult as seen in the next image:
http://figshare.com/articles/Complicated/1555855
The approach above will not work on this image as vessels from each year overrun so using the maximum y coordinates will not return the correct result.
So can anyone suggest another approach which may overcome this limitation? I have thought about using spatialpolygons but not sure this will achieve what I am looking for.
If you are creating the lines by clicking on the plot, you can use raster function drawLine or, for polygons, drawPoly. You could rasterize the polygons and mask that with the original image to get the vessels grouped by polygon (year).

Extracting boundary line from Image in R

So I got some kind of cross section picture in jpg format I want to work with. For better understanding I just drew a picture, hopefully symbolising well enough kinda how the real pictures will look like:
At the top of the picture is material A, at the bottom material B.
Goal: I want to get the Pixels of the boundary line between both materials.
My way so far:
I already know how to read pictures with package called EBImage
I also know, that this will result in a matrix with a color value for
every pixel.
I thought it would be better to convert the jpeg into a binary picture with only black and white colors.
I thought filling up the black part below (Material B) and reducing the noise would be nice, so I could use column sums (a sum of 1's) to find the row number where material A touches material B, which should be my searched boundary line (right?).
Problems:
I don't find filters which fill up the black parts intelligently, in the real pictures, there will be much more noise, which will complicate things even further...
I am not sure if all this is even necessary, and there is a more efficient way to reach my goal of finding the boundary line
Thank you very much for every tip in advance!
Answers will always be vague when there's no example to work with. I would normally use ImageJ for a task like this but EBImage has the commands that I would use.
From EBImage I would make binary and then erode , dilate, and fill holes (fillHull).
Your picture looks like it might be a candidate for a support vector machine. There are a couple of packages for R with svm functions, one is e1071.

visualization - size of circle proportionate to the value of the item

I'm getting familiar with Graphviz and wonder if it's doable to generate a diagram/graph like the one below (not sure what you call it). If not, does anyone know what's a good open source framework that does it? (pref, C++, Java or Python).
According to Many Eyes‌​, this is a bubble chart. They say:
It is especially useful for data sets with dozens to hundreds of values, or with values that differ by several orders of magnitude.
...
To see the exact value of a circle on the chart, move your mouse over it. If you are charting more than one dimension, use the menu to choose which dimension to show. If your data set has multiple numeric columns, you can choose which column to base the circle sizes on by using the menu at the bottom of the chart.
Thus, any presentation with a lot of bubbles in it (especially with many small bubbles) would have to be dynamic to respond to the mouse.
My usual practice with bubble charts is to show three or four variables (x, y and another variable through the size of the bubble, and perhaps another variable with the color or shading of the bubble). With animation, you can show development over time too - see GapMinder. FlowingData provides a good example with a tutorial on how to make static bubble charts in R.
In the example shown in the question, though, the bubbles appear to be located somewhat to have similar companies close together. Even then, the exact design criteria are unclear to me. For example, I'd have expected Volkswagen to be closer to General Motors than Pfizer is (if some measure of company similarity is used to place the bubbles), but that isn't so in this diagram.
You could use Graphviz to produce a static version of a bubble chart, but there would be quite a lot of work involved to do so. You would have to preprocess the data to calculate a similarity matrix, obtain edge weights from that matrix, assign colours and sizes to each bubble and then have the preprocessing script write the Graphviz file with all edges hidden and run the Graphviz file through neato to draw it.

Using R for extracing data from colour image

I have a scanned map from which i would like to extract the data into form of Long Lat and the corresponding value. Can anyone please tell me about how i can extract the data from the map. Is there any packages in R that would enable me to extract data from the scanned map. Unfortunately, i cannot find the person who made this map.
Thanks you very much for your time and help.
Take a look at OCR. I doubt you'll find anything for R, since R is primarily a statistical programming language.
You're better off with something like opencv
Once you find the appropriate OCR package, you will need to identify the x and y positions of your characters which you can then use to classify them as being on the x or y axis of your map.
This is not trivial, but good luck
Try this:
Read in the image file using the raster package
Use the locator() function to click on all the lat-long intersection points.
Use the locator data plus the lat-long data to create a table of lat-long to raster x-y coordinates
Fit a radial (x,y)->(r,theta) transformation to the data. You'll be assuming the projected latitude lines are circular which they seem to be very close to but not exact from some overlaying I tried earlier.
To sample from your image at a lat-long point, invert the transformation.
The next hard problem is trying to get from an image sample to the value of the thing being mapped. Maybe take a 5x5 grid of pixels and average, leaving out any gray pixels. Its even harder than that because some of the colours look like they are made from combining pixels of two different colours to make a new shade. Is this the best image you have?
I'm wondering what top-secret information has been blanked out from the top left corner. If it did say what the projection was that would help enormously.
Note you may be able to do a lot of the process online with mapwarper:
http://mapwarper.net
but I'm not sure if it can handle your map's projection.

Resources