Read and index data from .raw volume file with Java - java

I am working with volume data in raw format. I think that it is basically a 3D matrix of voxels that I want to load into a 3D array. I have no experience with this, and I’m unable to find much information on how it is done.
My main problem is that I don’t really understand what the data represents.
So what I’m asking really if anybody can help me to understand the data and load it into a 3D array with Java.

You're correct in thinking the first thing you need to do is understand the data. Here's a good explanation of what you're likely dealing with: https://support.echoview.com/WebHelp/Reference/File_formats/Export_file_formats/Volume_data_set_file_formats.htm#data_file
The .raw file probably contains a sequence of unsigned 8 bit integers. It's hard to say exactly without seeing the file (i.e. does it have a header, what is the matrix size, etc.)
Here's an answer that shows one method of converting from a 3D vector to a volume index and back in Java: https://stackoverflow.com/a/34363187/1973135. You'll need to know the actual dimension of the matrix to get this to work.

Related

How to access the raw image data

I'm using metadata-extractor to write a Java application that organizes images and finds duplicates. The API is great, but there's something I cannot figure out.
Suppose I have two JPG images. These images, visually, are exactly the same (i.e. same pixel-wise). However, maybe something within the metadata encapsulated in the file differs.
If I calculate MD5 hashes on each complete file, I will get two different hashes. However, I want to calculate a hash of only the image/pixel data, which would yield the same hash for both files.
So - Is there a way to pull out the raw image/pixel data from the JPG using metadata-extractor so that I can calculate my hash on this?
Also, is Javadoc available for this API? I cannot seem to find it.
You can achieve this using the library's JpegSegmentReader class. It'll let you pull out the JPEG segments that contain image data and ignore metadata segments.
I discussed this technique in another answer and the asker indicated they had success with the approach.
This would actually make a nice sample application for the library. If you come up with something and feel like sharing, please do.

Output of 2D DFT in jTransforms

I'm trying to write a high/low pass image filter using jtransforms. Everything is working very nicely in the sense that I can transform an image using the complexForward method of the FloatFFT_2D class, and then come back to exactly the same picture using the complexInverse method. I'm using a float[] input rather than a float[][].
However, to apply the filter I need to remove some of the frequency components in between these two stages. My problem is that I don't know what the output looks like, or in other words, where within the output array the different spatial frequencies are stored. Is a[0] the DC value, for example?
The documentation isn't particularly forthcoming on this, so I'd be grateful if anyone knew the answer!
Figured it out - the low frequency components are in the corners. So if you need the low frequency components to be at the centre, a java version of fftshift needs to be implemented as explained in the link below:
http://www.mathworks.co.uk/help/matlab/ref/fftshift.html

JTransforms FFT on Image

I have an image that I want to transform to the frequency domain using FFT, there seems to be a lack of libraries for this for Java but I have found two. One is JTransforms and the other was less well known and doesn't have a name.
With the less well known one the 2D could only have length vales of powers of two but had simple to use methods like FastFourierTransform.fastFT(real, imaginary, true); with the real being the 2D array of doubles full of every pixel values and the imaginary part being a 2D array the same size full of zeroes. The Boolean value would depend on a forward or reverse transform. This made sense to me and it worked except for the power of two requirement which ruined any transform I did (I initially added black space around the image to fit it to the closest power of two), what I am struggling with is working out how to use the equivalent methods for JTransforms and would appreciate any guidance in doing so. I will state what I am currently doing.
I believe the relevant class would be DoubleFFT_2D, its constructor takes a number of rows and columns which I would assume to be the width and height of my image. Because my image has no imaginary parts I think I can use doubleFFT.realForwardFull(real); which treats imaginary parts as zero and pass the real 2D array full of pixels. Unfortunately this doesn't work at all. The JavaDoc states the input array must be of size rows*2*columns, with only the first rows*columns elements filled with real data But I don't see how this related to my image and what I would have to do to meet this requirement.
Sorry about the lengthy and poor explanation, if any additional information is needed I would be happy to provide it.
JTransforms Library and Docs can be found here: https://sites.google.com/site/piotrwendykier/software/jtransforms
It's too bad the documentation for JTransforms isn't available online other than a zipped download. It's very complete and helpful, you should check it out!
To answer your question: DoubleFFT_2D.realForwardFull(double[][] a) takes an array of real numbers (your pixels). However, the result of the FFT will have two output values for each input value - a the real and the imaginary part of each frequency bin. This is why your input array needs to be twice as big as the actual image array, with half of it empty / filled with zeroes.
Note that all the FFT functions use a not only for input, but also for output - this means any image data in there will be lost, so it might be desirable to copy to a different / larger array anyway!
The easy and obvious fix for your scenario would be to use DoubleFFT_2D.realForward(double[][] a) instead. This one will only calculate the positive spectrum, because the negative side will be symmetrical to it. This is because your input values are real.
Also, check out the RealFFTUtils_2D class in JTransforms, which will make it a lot easier for you to retrieve your results from the array afterwards :)

How does LWJGL store it's matrix3f data?

Can someone tell me what order LWJGL stores it's materix3f data?
http://lwjgl.org/javadoc/org/lwjgl/util/vector/Matrix3f.html
I want to recreate the middle matrix (R.y) in this image:
http://upload.wikimedia.org/wikipedia/en/math/5/1/4/5148f88bf9e6811e35615c08d2839793.png
So, like would that -sin(angle) be in m.02, or m.20?
Whereas the storage order may differ when stored as a simple 1D-array, you can always be sure of the order when seeing double-indexed members, like m02. In these, the first number is the row and the second is the column.
This is the mathematical convention and is used by any matrix library I know. You can safely assume LWJGL to behave the same. If it really doesn't, write them a hate mail for doing such mathematically inconsistent rubbish.
So -sin goes into m20.

How do you pass a 2d array from java to flex(using BlazeDs)?

To date I have only managed to pass primitive types and Arrays to flex.
I need to know how to pass more complex objects like 2D arrays, or lists?
Are these sent in the same manner? and if so how are they unpackaged and displayed in say a datagrid?
I have searched for a long time for some help on this but cant find anything.
Any help will be greatly appreciated!
Thanks
You do not have to do anything special...all the rules related to serialization can be found here. As you can read, the instances of java.util.Collection are going to be serialized to ArrayCollection, and the array to Array. For practice just create a bunch of methods returning whatever you want and on the Flex side inspect the event.result object.
The question about how to display the data into a datagrid is a little bit too general - You need a structure with 2 dimension or a list of complex objects for sure. If you take a look on the BlazeDS samples folder you will find some examples doing that.

Categories

Resources