Large matrix handling

  • Follow


Hi,

  I need to deal with a very large matrix in Matlab, i.e. image(21600, 43200). With a floating point type, this matrix will take more than 3 GB memory. With a 64-bit machine and OS, this amount of memory can be allocated. But Matlab seems not be able to allocate that much of memory automatically. Does anybody have successful experience with similar situation?

Thanks in advance. 
0
Reply Tom 1/4/2010 4:38:04 PM

"Tom Nimbus" <ravensalo@gmail.com> wrote in message <hht5hc$evt$1@fred.mathworks.com>...
> Hi,
> 
>   I need to deal with a very large matrix in Matlab, i.e. image(21600, 43200). With a floating point type, this matrix will take more than 3 GB memory. With a 64-bit machine and OS, this amount of memory can be allocated. But Matlab seems not be able to allocate that much of memory automatically. Does anybody have successful experience with similar situation?
===============================

If it works on a 64-bit machine, why not use that?

Generally speaking though, loading such a large matrix into memory sounds like it could be a brute force solution. If you tell us more about the structure of the matrix, people may be able to suggest more efficient, structured solutions. In particular, is the matrix sparse? See "help sparse", if you're not familiar with sparse MATLAB arrays.
0
Reply Matt 1/4/2010 5:52:04 PM


"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hht9s4$p0i$1@fred.mathworks.com>...
> "Tom Nimbus" <ravensalo@gmail.com> wrote in message <hht5hc$evt$1@fred.mathworks.com>...
> > Hi,
> > 
> >   I need to deal with a very large matrix in Matlab, i.e. image(21600, 43200). With a floating point type, this matrix will take more than 3 GB memory. With a 64-bit machine and OS, this amount of memory can be allocated. But Matlab seems not be able to allocate that much of memory automatically. Does anybody have successful experience with similar situation?
> ===============================
> 
> If it works on a 64-bit machine, why not use that?
> 
> Generally speaking though, loading such a large matrix into memory sounds like it could be a brute force solution. If you tell us more about the structure of the matrix, people may be able to suggest more efficient, structured solutions. In particular, is the matrix sparse? See "help sparse", if you're not familiar with sparse MATLAB arrays.
> ===============================

Matt, thanks for your replying. Yes, this is a sparse array. It contains data from a large image, in which a lot of pixels are blank with scattered clusters. It's impossible to find good ways to divide the image without affecting the integrity of any cluster in the image. My problem is to load this image into Matlab. Due to the limitation of a 32-bit system, it's not possible to allocate memory above 4 GB. So I tried the 64-bit system, but Matlab still gave me the "out of memory" error. 
0
Reply Tom 1/5/2010 1:05:04 AM

"Tom Nimbus" <ravensalo@gmail.com> wrote in message <hhu380$3f4$1@fred.mathworks.com>...
> "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hht9s4$p0i$1@fred.mathworks.com>...
> > "Tom Nimbus" <ravensalo@gmail.com> wrote in message <hht5hc$evt$1@fred.mathworks.com>...
> > > Hi,
> > > 
> > >   I need to deal with a very large matrix in Matlab, i.e. image(21600, 43200). With a floating point type, this matrix will take more than 3 GB memory. With a 64-bit machine and OS, this amount of memory can be allocated. But Matlab seems not be able to allocate that much of memory automatically. Does anybody have successful experience with similar situation?
> > ===============================
> > 
> > If it works on a 64-bit machine, why not use that?
> > 
> > Generally speaking though, loading such a large matrix into memory sounds like it could be a brute force solution. If you tell us more about the structure of the matrix, people may be able to suggest more efficient, structured solutions. In particular, is the matrix sparse? See "help sparse", if you're not familiar with sparse MATLAB arrays.
> > ===============================
> 
> Matt, thanks for your replying. Yes, this is a sparse array. It contains data from a large image, in which a lot of pixels are blank with scattered clusters. It's impossible to find good ways to divide the image without affecting the integrity of any cluster in the image. My problem is to load this image into Matlab. Due to the limitation of a 32-bit system, it's not possible to allocate memory above 4 GB. So I tried the 64-bit system, but Matlab still gave me the "out of memory" error. 
=========================

You might be able to use memmapfile() to access the image file on disk from MATLAB. Then you can convert the data to a sparse matrix, at which point it will presumably occupy much less memory. Then you can save the sparse matrix to a .mat file.
0
Reply Matt 1/5/2010 2:59:04 AM

For an example of something similar using memory mapping see
http://www.mathworks.com/matlabcentral/fileexchange/17992-3d-cube-slice
0
Reply Malcolm 1/5/2010 4:20:19 PM

"Tom Nimbus" <ravensalo@gmail.com> wrote in message <hhu380$3f4$1@fred.mathworks.com>...

> Matt, thanks for your replying. Yes, this is a sparse array. It contains data from a large image, in which a lot of pixels are blank with scattered clusters. It's impossible to find good ways to divide the image without affecting the integrity of any cluster in the image. My problem is to load this image into Matlab. Due to the limitation of a 32-bit system, it's not possible to allocate memory above 4 GB. So I tried the 64-bit system, but Matlab still gave me the "out of memory" error. 
=================

Yet another option might be to load the image in chunks using fread() and conver it to a sparse array piece-by-piece.
0
Reply Matt 1/5/2010 5:22:05 PM

> =================
> 
> Yet another option might be to load the image in chunks using fread() and conver it to a sparse array piece-by-piece.

Thanks a million, Matt. This is a brilliant idea and it works pretty well. 
0
Reply Tom 1/6/2010 1:38:04 AM

"Tom Nimbus" <ravensalo@gmail.com> wrote in message <hi0phs$q1v$1@fred.mathworks.com>...
> 
> > =================
> > 
> > Yet another option might be to load the image in chunks using fread() and conver it to a sparse array piece-by-piece.
> 
> Thanks a million, Matt. This is a brilliant idea and it works pretty well. 

I'm not sure whether this came out in the discussion, but for reference
I just tried 
>> grunk = rand([21600,43200]);
>>image(grunk)
>> whos
  Name           Size                    Bytes  Class     Attributes

  grunk      21600x43200            7464960000  double              

>> 
without problem.
Win7, x64, 12GBytes RAM.
(The rand()  took a while & not sure how many real pixels I got in the image displayed.)
0
Reply nanren888 1/6/2010 6:52:02 AM

7 Replies
294 Views

(page loaded in 0.393 seconds)

Similiar Articles:













7/26/2012 1:17:14 AM


Reply: