Results 1 to 14 of 14
- 06-12-2011, 03:43 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Create Image from Arbitrary 2D Matrix of Data
Hi,
I have a 2D matrix of floats with each value corresponding to certain data value. The matrix is very large ~4000x4000 and I would like to display this matrix as an image, similar to MATLABs imagesc. I think I can do this by first finding the max and min of the image and scaling each element between 0 and 1, but I want to keep the original data values, and I feel there should be a way to keep the original data matrix and display it. Any help here would be greatly appreciated.
Thanks,
Dave
- 06-12-2011, 04:01 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Does a BufferedImage help you out?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-12-2011, 04:24 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
I should have mentioned that I have been trying that. I think a problem is that I don't think I know how to use BufferedImage correctly. For example, one data set I have has a range of floats from 0-150. I create a bufferedimage like so:
I then pull the data from a .dat file and load the image like so:Java Code:BufferedImage image = new BufferedImage(4000, 4000, BufferedImage.TYPE_INT_RGB
Which gives me an image but only in the blue range. I want the data to be imaged across red, green, and blue, while still preserving the original data value.Java Code:image.setRGB(ii,jj,(int) bf.order(ByteOrder.LITTLE_ENDIAN).getFloat())
Hope this provides a little motivation. Thanks
- 06-12-2011, 04:37 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
A BufferedImage internally uses ints for its pixel colors; you are just casting a float value (in the range [0,150]) to an int and use that for a color value; an int is of the form ARGB (four bytes), representing the alpha value, red, green and blue (as its least significant byte); that's why you only get blue-ish values in your image. Only if you're able to find a bijective function f(float) -> int there is no need to separately keep those floating point values because you can always get them back again from the BufferedImage; otherwise you're out of luck. b.t.w. do those floating point values represent color values or just scales of grey? If the latter, a bit of scaling can serve as your bijective function.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-12-2011, 04:42 PM #5
Create an array of 151 RGB/Color elements and index it with the numeric values
- 06-12-2011, 05:58 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Norm, the problem with that is that the range [0,150] are not integers, they are rational floats so I can't simply make a mapping like that.
Jos, So are you saying map my range [0-150] linearly to [0-16777215]? This might be suitable for my problem, but I just feel like there is a more elegant and efficient solution, as I feel like this is not a unique problem to have.
I was looking into the WritableRaster class that accepts setPixels of float[]. Do you know more about this?
- 06-12-2011, 06:05 PM #7
Are there more than 151 different colors you want to display? If so, how many?
Map your numbers to the range of the total different colors you want to show.
- 06-12-2011, 08:07 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-12-2011, 08:09 PM #9
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Norm,
I guess I may need to be a bit more flexible and I can do something like 150 colors. My next problem is the actual mapping. I have a 150 x 3 matrix of color mappings with each row representing the RGB component, [0-1] for each entry. I think I need to somehow use a ColorModel to efficiently do this mapping. Can you provide any advice?
- 06-12-2011, 08:13 PM #10
I thought the problem was how to show a 4000X4000 grid with each square having one of 151 different colors.
So given an array of 151 different colors, use the contents of each x,y element to chose a color for that x,y square.
How do the values of the elements relate to the color you want to use to show it in a square?
- 06-12-2011, 08:35 PM #11
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Im pulling this colormap from MATLAB. I cant tell for sure but it seems to be the same idea as color model in Java. For the basic color model the lowest color is blue and the highest color is red. The colormap transitions linearly from blue through the rainbow to red. There are also color maps that may transition non-linearly. I suppose I could loop over each pixel everytime I want to change the colormodel, but it seems I shouldn't have to do this.
- 06-12-2011, 08:43 PM #12
Sorry, I'm not following your discussion about colormaps. I was simply using 151 different colors.
- 06-12-2011, 09:37 PM #13
Member
- Join Date
- Feb 2011
- Posts
- 27
- Rep Power
- 0
Ok, so using 151 colors may I ask how you would select the colors?
- 06-12-2011, 09:42 PM #14
Similar Threads
-
Matrix Data Assignment
By sehudson in forum New To JavaReplies: 5Last Post: 03-01-2011, 07:45 AM -
Matrix Data Type
By fraB3422 in forum New To JavaReplies: 7Last Post: 02-27-2011, 02:08 AM -
Arbitrary number of objects, each with a unique name.
By providence in forum New To JavaReplies: 8Last Post: 02-23-2011, 01:12 AM -
gradients between two arbitrary colors
By falkon114 in forum New To JavaReplies: 4Last Post: 02-09-2011, 05:08 PM -
Create a VeryLong class that will store an integer of arbitrary length.
By hey in forum New To JavaReplies: 2Last Post: 12-12-2007, 05:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks