|
| 1 | +classdef ImportImageFromBinaryFile < imagem.gui.Action |
| 2 | +% One-line description here, please. |
| 3 | +% |
| 4 | +% Class ImportImageFromBinaryFile |
| 5 | +% |
| 6 | +% Example |
| 7 | +% ImportImageFromBinaryFile |
| 8 | +% |
| 9 | +% See also |
| 10 | +% |
| 11 | + |
| 12 | +% ------ |
| 13 | +% Author: David Legland |
| 14 | + |
| 15 | +% Created: 2020-12-23, using Matlab 9.8.0.1323502 (R2020a) |
| 16 | +% Copyright 2020 INRAE - BIA-BIBS. |
| 17 | + |
| 18 | + |
| 19 | +%% Properties |
| 20 | +properties |
| 21 | +end % end properties |
| 22 | + |
| 23 | + |
| 24 | +%% Constructor |
| 25 | +methods |
| 26 | + function obj = ImportImageFromBinaryFile(varargin) |
| 27 | + % Constructor for ImportImageFromBinaryFile class. |
| 28 | + |
| 29 | + end |
| 30 | + |
| 31 | +end % end constructors |
| 32 | + |
| 33 | +%% Methods |
| 34 | +methods |
| 35 | + function run(obj, frame) %#ok<INUSL> |
| 36 | + disp('% Open new table '); |
| 37 | + |
| 38 | + % get handle to parent GUI |
| 39 | + gui = frame.Gui; |
| 40 | + |
| 41 | + [fileName, pathName] = uigetfile( ... |
| 42 | + {'*.raw;*.bin;*.tif;*.vol', 'All Binary Files (*.raw, *.bin, *.tif, *.vol)'; ... |
| 43 | + '*.tif,' 'Tif Files (*.tif)'; ... |
| 44 | + '*.raw,' 'Raw Files (*.raw)'; ... |
| 45 | + '*.vol,' 'Vol Files (*.vol)'; ... |
| 46 | + '*.*', 'All Files (*.*)'}, ... |
| 47 | + 'Choose a data table file to open:'); |
| 48 | + |
| 49 | + if isequal(fileName,0) || isequal(pathName,0) |
| 50 | + return; |
| 51 | + end |
| 52 | + |
| 53 | + % determine file options |
| 54 | + filePath = fullfile(pathName, fileName); |
| 55 | + [~, imageName] = fileparts(fileName); |
| 56 | + |
| 57 | + % creates a new dialog, and populates it with some fields |
| 58 | + dataTypes = {'uint8', 'uint16', 'int16', 'single', 'double'}; |
| 59 | + gd = imagem.gui.GenericDialog('Import Image'); |
| 60 | +% addNumericField(gd, 'Offset: ', 0); |
| 61 | + addNumericField(gd, 'Size X: ', 512); |
| 62 | + addNumericField(gd, 'Size Y: ', 512); |
| 63 | + addNumericField(gd, 'Size Z: ', 100); |
| 64 | + addChoice(gd, 'Type: ', dataTypes, dataTypes{1}); |
| 65 | + addCheckBox(gd, 'Little-endian', true); |
| 66 | + |
| 67 | + % displays the dialog, and waits for user |
| 68 | + showDialog(gd); |
| 69 | + % check if ok or cancel was clicked |
| 70 | + if wasCanceled(gd) |
| 71 | + return; |
| 72 | + end |
| 73 | + |
| 74 | + % parse the user inputs |
| 75 | + sizeX = getNextNumber(gd); |
| 76 | + sizeY = getNextNumber(gd); |
| 77 | + sizeZ = getNextNumber(gd); |
| 78 | + type = getNextString(gd); |
| 79 | + if getNextBoolean(gd) |
| 80 | + byteOrder = 'ieee-le'; |
| 81 | + else |
| 82 | + byteOrder = 'ieee-be'; |
| 83 | + end |
| 84 | + |
| 85 | + % read the image |
| 86 | + img = Image.importRaw(filePath, ... |
| 87 | + [sizeX sizeY sizeZ], ... |
| 88 | + type, 'byteOrder', byteOrder); |
| 89 | + img.Name = imageName; |
| 90 | + |
| 91 | + % add image to application, and create new display |
| 92 | + [frame, doc] = createImageFrame(gui, img); |
| 93 | + |
| 94 | + % add history |
| 95 | + string = sprintf('%s = Image.importRaw(''%s'', [%d %d %d], ''%s'', ''byteOrder'', ''%s'');\n', ... |
| 96 | + doc.Tag, filePath, sizeX, sizeY, sizeZ, type, 'byteOrder', byteOrder); |
| 97 | + addToHistory(frame, string); |
| 98 | + end |
| 99 | +end % end methods |
| 100 | + |
| 101 | +end % end classdef |
| 102 | + |
0 commit comments