Errors with dicomwrite

  • Follow


Has anyone come across this error before when using dicomwrite? I have just install Matlab 2009a on a new machine and brought over some of my dicom code (which used to work).

I try some thing simple like,

>> test = dicomread('../423/IM0200_0');
>> dicomwrite(test,'./test.dcm')

and I get these errors,

??? Index exceeds matrix dimensions.

Error in ==> dicom_generate_uid>create_machine_part at 164
    os_id = address(1:2);

Error in ==> dicom_generate_uid>get_matlab_instance at 104
        machine_part = create_machine_part(address, process);

Error in ==> dicom_generate_uid at 28
        matlab_instance = get_matlab_instance;

Error in ==> dicomuid at 14
uid = dicom_generate_uid('instance');

Error in ==> dicom_prep_FrameOfReference at 11
    metadata.(name) = dicomuid;

Error in ==> dicom_prep_metadata at 41
    metadata = dicom_prep_FrameOfReference(metadata);

Error in ==> dicom_create_IOD at 30
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr);

Error in ==> dicomwrite>write_message at 236
        [attrs, msg, status] = dicom_create_IOD(SOP_UID, X(:,:,:,p), map, ...

Error in ==> dicomwrite at 195
    status = write_message(X, filename, map, metadata, options);

I have confirmed that dicomread is fine, it seems I only get the error when I try to write,

any ideas from anyone would be helpful,

Dave 
0
Reply david.warne 7/28/2009 3:50:19 AM

David wrote:
> Has anyone come across this error before when using dicomwrite? I
> have just install Matlab 2009a on a new machine and brought over some
> of my dicom code (which used to work).

Hi David,

It would be great if you could contact technical support with your issue.

www.mathworks.com/support/

---
Steve Eddins
http://blogs.mathworks.com/steve/
0
Reply steve.eddins (783) 7/28/2009 11:10:20 AM


"Steve Eddins" wrote in message <h4mmas$blh$1@fred.mathworks.com>...
> David wrote:
> > Has anyone come across this error before when using dicomwrite? I
> > have just install Matlab 2009a on a new machine and brought over some
> > of my dicom code (which used to work).
> 
> Hi David,
> 
> It would be great if you could contact technical support with your issue.
> 
> www.mathworks.com/support/
> 
> ---
> Steve Eddins
> http://blogs.mathworks.com/steve/

Hello 
I am getting the same error.  I have code that works on a windows and LINUX machine.  When I try and run it on a different LINUX machine I get error above. What was the resolution to this error?

Thank you
Kerry
0
Reply kerry.danelson (1) 12/7/2011 10:47:08 AM

"Kerry Danelson" <kerry.danelson@gmail.com> wrote in message 
> > David wrote:
> > > Has anyone come across this error before when using dicomwrite? I
> > > have just install Matlab 2009a on a new machine and brought over some
> > > of my dicom code (which used to work).
> 
> Hello 
> I am getting the same error.  I have code that works on a windows and LINUX machine.  When I try and run it on a different LINUX machine I get error above. What was the resolution to this error?

This was fixed in R2010a. If you're still running into it on newer versions of MATLAB and the Image Processing Toolbox, please let us know.

Jeff Mather
Image Processing Group
MathWorks
0
Reply jeff.mather (70) 12/7/2011 8:11:07 PM

Hello!
I have this error and I am using R2010a.

Specifically,
>> meta_data.SeriesInstanceUID = dicomuid;
???  Index of element to remove exceeds matrix dimensions.

Error in ==> dicom_generate_uid>guid_to_uid at 117
guid(13) = '';

Error in ==> dicom_generate_uid at 36
        uid = guid_to_uid(ipt_root, guid_32bit);

Error in ==> dicomuid at 14
uid = dicom_generate_uid('instance');
 
>> 
>> version
ans =
7.10.0.499 (R2010a)


Any thoughts?  
Thank you!
Erika




"Jeff Mather" <jeff.mather@mathworks.com> wrote in message <jboh8r$po0$1@newscl01ah.mathworks.com>...
> "Kerry Danelson" <kerry.danelson@gmail.com> wrote in message 
> > > David wrote:
> > > > Has anyone come across this error before when using dicomwrite? I
> > > > have just install Matlab 2009a on a new machine and brought over some
> > > > of my dicom code (which used to work).
> > 
> > Hello 
> > I am getting the same error.  I have code that works on a windows and LINUX machine.  When I try and run it on a different LINUX machine I get error above. What was the resolution to this error?
> 
> This was fixed in R2010a. If you're still running into it on newer versions of MATLAB and the Image Processing Toolbox, please let us know.
> 
> Jeff Mather
> Image Processing Group
> MathWorks
0
Reply laingej (6) 3/7/2013 4:56:06 PM

Update: 
I upgraded to R2012b, just in case it was still an upgrade issue, and I still get the same error.  Help!

>> meta_data.SeriesInstanceUID = dicomuid;
Index of element to remove exceeds matrix dimensions.

Error in dicom_generate_uid>guid_to_uid (line 113)
guid(13) = '';

Error in dicom_generate_uid (line 36)
        uid = guid_to_uid(ipt_root, guid_32bit);

Error in dicomuid (line 14)
uid = dicom_generate_uid('instance');
 
>> version
ans =
8.0.0.783 (R2012b)


Also, I am running this on Fedora 17
other specs:
Linux loki 3.4.2-4.fc17.x86_64 #1 SMP Thu Jun 14 22:22:05 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Thanks
Erika
0
Reply laingej (6) 3/7/2013 6:39:07 PM

The error seems to be in it not knowing what
create_guid_linux()

is.  How can I fix that?
0
Reply laingej (6) 3/7/2013 7:14:08 PM

and by the way, dicomuid does work on another system I tested it on, which runs identical Fedora 17, but with matlab R2012a instead of R2012b

I can't use the other computer for this procedure though, so I need to solve this bug.
0
Reply laingej (6) 3/7/2013 7:24:08 PM

OK I really apologize for the play-by-play.  One last thing - I went overkill and installed R2012a on the machine dicomuid doesn't work on, and it still doesn't work.  So it is something idiosyncratic to the setup there?  Is there possibly some kind of library or something I am missing????
0
Reply laingej (6) 3/7/2013 8:15:08 PM

Seriously, this is the last one -- because it is solved!  Support team is awesome if you email them directly!!!  THANK YOU MATHWORKS, crazy awesome prompt customer support.

If you have a problem like me:

1. Find the $MATLABROOT directory where $MATLABROOT is the MATLAB root directory on your machine, as returned by typing the following command in MATLAB command prompt:
                              >>matlabroot
 
2. Quit MATLAB.
 
3. Rename the following M-file:
$MATLABROOT/toolbox/images/iptformats/private/dicom_generate_uid.m
 
4. Create a new file called dicom_generate_uid.m and put the code at the bottom of this message in it. Place the new file in the same directory mentioned in step 3 $MATLABROOT/toolbox/images/iptformats/private/
 
5. Restart MATLAB.
 
6. After restarting MATLAB, issue the following command at the MATLAB Command Prompt:
                              >>rehash toolboxcache
 
7. Try to execute DICOMUID command again.


========dicom_generate_uid.m=========

function uid = dicom_generate_uid(uid_type)
%DICOM_GENERATE_UID  Create a globally unique ID.
%   UID = DICOM_GENERATE_UID(TYPE) creates a unique identifier (UID) of
%   the specified type.  TYPE must be one of the following:
%
%      'instance'      - A UID for any arbitrary DICOM object
%      'ipt_root'      - The root of the Image Processing Toolbox's UID
%      'series'        - A UID for an arbitrary series of DICOM images
%      'study'         - A UID for an arbitrary study of DICOM series
%
%   See also MWGUIDGEN.

%   Copyright 1993-2012 The MathWorks, Inc.

% This is the UID root assigned to us.  It prevents collisions with UID
% generation schemes from other vendors.
ipt_root = '1.3.6.1.4.1.9590.100.1';

switch (uid_type)
case {'ipt_root'}
    
    uid = ipt_root;
    
case {'instance', 'series', 'study'}

    switch (lower(computer()))
    case {'pcwin', 'pcwin64'}
        
        guid_32bit = create_guid_windows();
        uid = guid_to_uid(ipt_root, guid_32bit);
        
    case {'glnxa64', 'glnx86'}
        
        guid_32bit = create_guid_linux();
        uid = guid_to_uid(ipt_root, guid_32bit);

    case {'maci', 'maci64'}
        
        guid_32bit = create_guid_mac();
        uid = guid_to_uid(ipt_root, guid_32bit);
    
    otherwise
    
        error(message('images:dicom_generate_uid:unsupportedPlatform'))
        
    end
    
otherwise
    
    error(message('images:dicom_generate_uid:inputValue', uid_type));
    
end



function guid_32bit = create_guid_linux

[status, raw_guid] = system('uuidgen');
if (status ~= 0)
    
    [status, raw_guid] = system('cat /proc/sys/kernel/random/uuid');
    if (status ~= 0)
        
        error(message('images:dicom_generate_uid:linuxSystemProblem'))
    
    end

end

tmp_guid = strip_unix_messages(raw_guid);
guid_32bit = sscanf(strrep(tmp_guid, '-', ''), '%08x');



function guid_32bit = create_guid_mac

[status, raw_guid] = system('uuidgen');
if (status ~= 0)
    
    error(message('images:dicom_generate_uid:macSystemProblem'))
    
end

tmp_guid = strip_unix_messages(raw_guid);
guid_32bit = sscanf(strrep(tmp_guid, '-', ''), '%08x');



function guid_32bit = create_guid_windows

% Generate a GUID as a series of 16 UINT8 values.
guid_8bit = mwguidgen;

% Convert the bytes to four UINT32 values.
guid_32bit = dicom_typecast(guid_8bit, 'uint32');



function uid = guid_to_uid(ipt_root, guid_32bit)

% Convert a group of numeric values into a concatenated string.
guid = '';
for p = 1:length(guid_32bit)
    
    guid = [guid sprintf('%010.0f', double(guid_32bit(p)))];  %#ok<AGROW>
    
end

% The maximum decimal representation of four concatenated 32-bit values
% is 40 digits long, which is one digit too many for the UID container in
% DICOM (after you add in the UID root).  Shorten it to fit in DICOM's
% length requirements by removing a value from the middle.  (As a result,
% 1 in every 10^39 values will be a duplicate.)
guid(13) = '';

% The DICOM standard requires the digit that follows a dot to be
% nonzero.  Removing the leading zeros does not cause duplication.
guid = remove_leading_zeros(guid);

% Append the GUID to the UID root. The intervening digit is the version
% number of the UID generation scheme.  Increment the version number if
% the rule/mechanism for generating "guid" changes. (The next scheme version
% number should be 4; skip 3, which is being used for implementation UIDs.)
uid = [ipt_root '.2.' guid];



function out = remove_leading_zeros(in)

out = in;
while (out(1) == '0')
    out(1) = '';
end



function out = strip_unix_messages(in)

% It's possible that sourcing a shell configuration file (or
% another part of the shell launch) causes a message to appear in
% the system() output. Strip out everything but the GUID value,
% which we must assume to be the last full line.

out = in;

newLine = sprintf('\n');
idx = find(in == newLine);

if (numel(idx) > 1)
  out(1:idx(end-1)) = '';
end
0
Reply laingej (6) 3/7/2013 10:02:07 PM

9 Replies
49 Views

(page loaded in 0.882 seconds)


Reply: