ImageJ-MATLAB's `IJM.show` freezes when opening an image of 2GB size

imagej
matlab
memory
imagej-matlab

#1

I’m using ImageJ-MATLAB’s IJM.show(name) to open an array of 2GB as an image in ImageJ, and everytime I end up crashing MATLAB.

java.lang.Runtime.getRuntime.maxMemory returns roughly 23 GB, because I’ve edited C:\Program Files\MATLAB\R2018a\bin\win64\java.opts to increase Java heap size.

It appears to me that the memory is big enought to handle this image.

>> memory
Maximum possible array:       44594 MB (4.676e+10 bytes) *
Memory available for all arrays:       44594 MB (4.676e+10 bytes) *
Memory used by MATLAB:        2821 MB (2.958e+09 bytes)
Physical Memory (RAM):       32673 MB (3.426e+10 bytes)

*  Limited by System Memory (physical + swap file) available.

System crash report says Access violation detected

MATLAB crash file:C:\Users\phar0528\AppData\Local\Temp\matlab_crash_dump.88720-1:


--------------------------------------------------------------------------------
          Access violation detected at Wed May 16 09:59:08 2018 +0100
--------------------------------------------------------------------------------

Configuration:
  Crash Decoding           : Disabled - No sandbox or build area path
  Crash Mode               : continue (default)
  Default Encoding         : windows-1252
  Deployed                 : false
  Graphics Driver          : Unknown hardware 
  Graphics card 1          : Intel Corporation ( 0x8086 ) Intel(R) HD Graphics 4600 Version 20.19.15.4835 (2017-10-16)
  Java Version             : Java 1.8.0_144-b01 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  MATLAB Architecture      : win64
  MATLAB Entitlement ID    : 1980484
  MATLAB Root              : C:\Program Files\MATLAB\R2018a
  MATLAB Version           : 9.4.0.813654 (R2018a)
  OpenGL                   : hardware
  Operating System         : Microsoft Windows 10 Pro
  Process ID               : 88720
  Processor ID             : x86 Family 6 Model 60 Stepping 3, GenuineIntel
  Session Key              : cf0751e7-a7b7-4094-9768-4605bc077d4a
  Window System            : Version 10.0 (Build 16299)

Fault Count: 1


Abnormal termination

Register State (from fault):
  RAX = 0000000000000002  RBX = 000000002bcfe000
  RCX = 00000005014c5320  RDX = 00000009d0a16cc0
  RSP = 00000000043f98c8  RBP = 0000000110f6f4a0
  RSI = 0000000000000000  RDI = 00000000ce0a2da0
 
   R8 = fffffffe00000da0   R9 = 0000000000000000
  R10 = 0000000000000000  R11 = 00000003334223a0
  R12 = 0000000000000000  R13 = 000000000780f560
  R14 = 0000000d03e39060  R15 = 0000000000000000
 
  RIP = 000000005219c0a6  EFL = 00010202
 
   CS = 0033   FS = 0053   GS = 002b

Stack Trace (from fault):
[  0] 0x000000005219c0a6 C:\Program Files\MATLAB\R2018a\sys\java\jre\win64\jre\bin\MSVCR100.dll+00245926 memmove+00000326
[  1] 0x00000000513ada32 C:\Program Files\MATLAB\R2018a\sys\java\jre\win64\jre\bin\server\jvm.dll+01432114 JNI_GetCreatedJavaVMs+00133298
[  2] 0x00000000fa71698d                            bin\win64\nativejmi.dll+00289165 NativeLabCmdWinSetup+00020045
[  3] 0x00000000fa70d798                            bin\win64\nativejmi.dll+00251800 nativejmi::JmiFEvalIIP::write+00011528
[  4] 0x00000000fcff8f38                                  bin\win64\iqm.dll+00429880 iqm::BaseFEvalPlugin::execute+00000792
[  5] 0x00000000fa70dbae                            bin\win64\nativejmi.dll+00252846 nativejmi::JmiFEvalIIP::write+00012574
[  6] 0x00000000fa7567a0                            bin\win64\nativejmi.dll+00550816 NativeLabCmdWinSetup+00281696
[  7] 0x00000000fcfed9ea                                  bin\win64\iqm.dll+00383466 iqm::Iqm::setupIqmFcnPtrs+00071994
[  8] 0x00000000fcfed84c                                  bin\win64\iqm.dll+00383052 iqm::Iqm::setupIqmFcnPtrs+00071580
[  9] 0x00000000fcfd2490                                  bin\win64\iqm.dll+00271504 iqm::Iqm::deliver+00019456
[ 10] 0x00000000fcfc41b7                                  bin\win64\iqm.dll+00213431 iqm::IqmInputRequestEvent::~IqmInputRequestEvent+00009751
[ 11] 0x00000000fd7d7b23                               bin\win64\mlutil.dll+01866531 cmddistributor::IIPRunNowMessage::deliver+00000035
[ 12] 0x000000001321621b                              bin\win64\libmwms.dll+01270299 foundation::msg_svc::exchange::MessageQueue::deliver+00000171
[ 13] 0x0000000013216bd5                              bin\win64\libmwms.dll+01272789 foundation::msg_svc::exchange::MessageQueue::sendReply+00002005
[ 14] 0x0000000013204c2a                              bin\win64\libmwms.dll+01199146 foundation::msg_svc::exchange::CommunicationErrorEvent::getIsError+00072010
[ 15] 0x000000001320f8fc                              bin\win64\libmwms.dll+01243388 foundation::msg_svc::exchange::CommunicationErrorEvent::getIsError+00116252
[ 16] 0x000000001320ef87                              bin\win64\libmwms.dll+01240967 foundation::msg_svc::exchange::CommunicationErrorEvent::getIsError+00113831
[ 17] 0x00000000fd6da058                               bin\win64\mlutil.dll+00827480 cmddistributor::IIP::EventMgrBypass::operator=+00037784
[ 18] 0x00000000fd6ae6b3                               bin\win64\mlutil.dll+00648883 cmddistributor::DebugLoopEvent::serializeExplicit+00012515
[ 19] 0x00000000fa73cd03                            bin\win64\nativejmi.dll+00445699 NativeLabCmdWinSetup+00176579
[ 20] 0x00000000fa74481f                            bin\win64\nativejmi.dll+00477215 NativeLabCmdWinSetup+00208095
[ 21] 0x00000000fa73ddbf                            bin\win64\nativejmi.dll+00449983 NativeLabCmdWinSetup+00180863
[ 22] 0x00000000fa73e06f                            bin\win64\nativejmi.dll+00450671 NativeLabCmdWinSetup+00181551
[ 23] 0x00000000fa7216f4                            bin\win64\nativejmi.dll+00333556 NativeLabCmdWinSetup+00064436
[ 24] 0x00000000fa7410e8                            bin\win64\nativejmi.dll+00463080 NativeLabCmdWinSetup+00193960
[ 25] 0x00000000fa741256                            bin\win64\nativejmi.dll+00463446 NativeLabCmdWinSetup+00194326
[ 26] 0x00000000fa738145                            bin\win64\nativejmi.dll+00426309 NativeLabCmdWinSetup+00157189
[ 27] 0x000000006c0e81b4                                   <unknown-module>+00000000
[ 28] 0x00000000576f8eb8                                   <unknown-module>+00000000
[ 29] 0x00000000512ea65f C:\Program Files\MATLAB\R2018a\sys\java\jre\win64\jre\bin\server\jvm.dll+00632415 JVM_GetManagementExt+00484063


I’ve found a similar crash report here

https://uk.mathworks.com/matlabcentral/answers/283898-abnormal-termination-access-violation

Any idea to solve this problem, please?


#2

I’ve asked the same question elsewhere.

https://uk.mathworks.com/matlabcentral/answers/401182-imagej-matlab-s-ijm-show-freezes-when-opening-an-image-of-2gb-size


#3

I ended up writing an alternative to copytoImg or copytoImgPlus in FIji, called copytoImagePlus.

As the name suggests, it returns ImageJ1 ImagePlus object, instead of ImageJ2 objects. Although they serve for the same purpose, copytoImagePlus does not rely on IJM.show(), and appears to be more reliable.

I was able to open 2GB file with copytoImagePlus.