|
| 1 | ++++ |
| 2 | +title = "Critical Bugfix" |
| 3 | +date = 2014-01-15T19:49:49+01:00 |
| 4 | +updated = 2014-01-15T19:49:49+01:00 |
| 5 | +draft = false |
| 6 | +template = "blog/page.html" |
| 7 | + |
| 8 | +[taxonomies] |
| 9 | +authors = ["Markus Diem"] |
| 10 | ++++ |
| 11 | + |
| 12 | +we have found a critical bug which – in some cases – prevents nomacs from starting correctly. |
| 13 | +If you experience this issue, we would recommend to update nomacs to version 1.6.3. |
| 14 | + The issue applies only to the Windows versions. |
| 15 | +Users of other OS can safely enjoy version 1.6.2. |
| 16 | +Sorry for any inconveniences caused. |
| 17 | +For the Matlab users who do not enjoy the default image display behavior of Matlab: |
| 18 | +this script allows you to directly display images in nomacs. |
| 19 | + |
| 20 | +```matlab |
| 21 | +function nomacs(img, varargin) |
| 22 | +% nomacs(img, varargin) |
| 23 | +% |
| 24 | +% nomacs displays the image img in nomacs |
| 25 | +% |
| 26 | +% INPUT: |
| 27 | +% img the image to display |
| 28 | +% |
| 29 | +% normalize displays the image in the range between [val1 val2]. If the |
| 30 | +% parameter is set to [] the image is normalized between |
| 31 | +% min(img(:)) and max(img(:)). Note: It is possible to pass |
| 32 | +% the following parameter struct as a second parameter, if |
| 33 | +% normalization should not be performed. |
| 34 | +% |
| 35 | +% tempFolder the folder where the image is saved temporary (it is |
| 36 | +% deleted afterwards |
| 37 | +% |
| 38 | +% exePath specify the exePath if it is not in Program Files (x86) |
| 39 | +
|
| 40 | +if isempty(img) |
| 41 | + return; |
| 42 | +elseif size(img,4) > 4 |
| 43 | + warning('NOMACS:falseImg', ['The number of channels must not be '... |
| 44 | + 'greater than four.']); |
| 45 | + return; |
| 46 | +end |
| 47 | +
|
| 48 | +p = parse_inputs(varargin{:}); |
| 49 | +
|
| 50 | +% check if nomacs is up & running |
| 51 | +if ~exist(strrep(p.exePath, '"', ''), 'file') |
| 52 | + display( p.exePath); |
| 53 | + error('NOMACS:notFound', ['Sorry, I could not locate nomacs.exe \n'... |
| 54 | + 'Please specify the correct exePath.']); |
| 55 | +end |
| 56 | +
|
| 57 | +if isfield(p, 'normalize') |
| 58 | + |
| 59 | + if isempty(p.normalize) |
| 60 | + |
| 61 | + img = im2double(img); |
| 62 | + img = img-min(img(:)); |
| 63 | + img = img./max(img(:)); |
| 64 | +
|
| 65 | + elseif length(p.normalize) == 2 |
| 66 | + n = p.normalize; |
| 67 | + img = double(img); |
| 68 | + img = img-n(1); |
| 69 | + img = img./(n(2) - n(1)); |
| 70 | + end |
| 71 | +end |
| 72 | +
|
| 73 | +imwrite(img, p.tempFolder); |
| 74 | +
|
| 75 | +if ~isunix |
| 76 | + system([p.exePath ' ' p.tempFolder ' &']); |
| 77 | +else |
| 78 | + unix([p.exePath ' ' p.tempFolder ' &']); |
| 79 | +end |
| 80 | +
|
| 81 | +delete(p.tempFolder); |
| 82 | +
|
| 83 | +%------------------------------------------------------------------------- |
| 84 | +% Subfunction: Parse Inputs |
| 85 | +%------------------------------------------------------------------------- |
| 86 | +function params = parse_inputs(varargin) |
| 87 | +
|
| 88 | +% called with normaliztion only |
| 89 | +if nargin == 1 && isfloat(varargin{1}) |
| 90 | + params.normalize = varargin{1}; |
| 91 | +% second param is the struct |
| 92 | +elseif nargin == 1 && isstruct(varargin{1}) |
| 93 | + params = varargin{1}; |
| 94 | +% three parameters (img, [], p) |
| 95 | +elseif nargin == 2 && isfloat(varargin{1}) && isstruct(varargin{2}) |
| 96 | + params = varargin{2}; |
| 97 | + params.normalize = varargin{1}; |
| 98 | +% no params |
| 99 | +elseif nargin == 0 |
| 100 | + params = []; |
| 101 | +else |
| 102 | + warning('NOMACS:paramFalse', ['The input parameters do not'... |
| 103 | + ' conform to the required schema. Using default parameters'... |
| 104 | + ' instead.']); |
| 105 | +end |
| 106 | +
|
| 107 | +if ~isunix |
| 108 | + |
| 109 | + try |
| 110 | + exename = winqueryreg('HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\nomacs.exe'); |
| 111 | + catch |
| 112 | + exename = fullfile('C:', 'Program Files (x86)','nomacs', 'nomacs.exe'); |
| 113 | + end |
| 114 | + imgname = fullfile(tempdir, 'matlab-nomacs.tif'); |
| 115 | +else |
| 116 | + exename = ''; % TODO |
| 117 | + imgname = ''; % TODO |
| 118 | +end |
| 119 | +
|
| 120 | +% define vars |
| 121 | +default_params.exePath = ['"' exename '"']; |
| 122 | +default_params.tempFolder = imgname; |
| 123 | +
|
| 124 | +params = merge_structs(params, default_params); |
| 125 | +
|
| 126 | +
|
| 127 | +%------------------------------------------------------------------------- |
| 128 | +% Subfunction: Merge Structs |
| 129 | +%------------------------------------------------------------------------- |
| 130 | +function struct2 = merge_structs(struct1, struct2) |
| 131 | +% function new_struct = merge_structs(struct1, struct2) |
| 132 | +% |
| 133 | +% Merges both STRUCTs. |
| 134 | +% All values where both structs have the same fieldnames are taken from |
| 135 | +% STRUCT1. The NEW_STRUCT contains the fields of both STRUCTS. |
| 136 | +
|
| 137 | +
|
| 138 | +if isempty(struct1) |
| 139 | + return; |
| 140 | +end |
| 141 | +
|
| 142 | +names = fieldnames(struct1); |
| 143 | +
|
| 144 | +for i = 1:length(names) |
| 145 | + struct2.(names{i}) = struct1.(names{i}); |
| 146 | +end |
| 147 | +``` |
| 148 | + |
| 149 | +— the nomacs team |
0 commit comments