|
| 1 | +classdef BinaryImageOverlay < imagem.gui.Action |
| 2 | +% Apply binary overlay over current image. |
| 3 | +% |
| 4 | +% Class ImageOverlayAction |
| 5 | +% |
| 6 | +% Example |
| 7 | +% ImageOverlayAction |
| 8 | +% |
| 9 | +% See also |
| 10 | +% |
| 11 | + |
| 12 | +% ------ |
| 13 | +% Author: David Legland |
| 14 | + |
| 15 | +% Created: 2011-12-15, using Matlab 7.9.0.529 (R2009b) |
| 16 | +% Copyright 2011 INRA - Cepia Software Platform. |
| 17 | + |
| 18 | + |
| 19 | +%% Properties |
| 20 | +properties |
| 21 | +end % end properties |
| 22 | + |
| 23 | + |
| 24 | +%% Constructor |
| 25 | +methods |
| 26 | + function obj = BinaryImageOverlay() |
| 27 | + end |
| 28 | + |
| 29 | +end % end constructors |
| 30 | + |
| 31 | +methods |
| 32 | + function run(obj, frame) %#ok<INUSL> |
| 33 | + |
| 34 | + app = frame.Gui.App; |
| 35 | + imageNames = getImageNames(app); |
| 36 | + colorNames = imagem.util.enums.BasicColors.allLabels; |
| 37 | + |
| 38 | + % Creates the Dialogfor choosing options |
| 39 | + gd = imagem.gui.GenericDialog('Binary Overlay'); |
| 40 | + addChoice(gd, 'Reference Image:', imageNames, imageNames{1}); |
| 41 | + addChoice(gd, 'Binary Image:', imageNames, imageNames{1}); |
| 42 | + addChoice(gd, 'Overlay Color:', colorNames, colorNames{1}); |
| 43 | + |
| 44 | + % displays the dialog, and waits for user |
| 45 | + showDialog(gd); |
| 46 | + % check if ok or cancel was clicked |
| 47 | + if wasCanceled(gd) |
| 48 | + return; |
| 49 | + end |
| 50 | + |
| 51 | + % parse user inputs |
| 52 | + refDoc = getDocument(app, getNextString(gd)); |
| 53 | + binDoc = getDocument(app, getNextString(gd)); |
| 54 | + colorItem = imagem.util.enums.BasicColors.fromLabel(getNextString(gd)); |
| 55 | + color = colorItem.RGB; |
| 56 | + |
| 57 | + % retrieve images |
| 58 | + refImg = refDoc.Image; |
| 59 | + binImg = binDoc.Image; |
| 60 | + |
| 61 | + % check inputs |
| 62 | + if ~isBinaryImage(binImg) |
| 63 | + error('Overlay Image must be binary'); |
| 64 | + end |
| 65 | + if ndims(refImg) ~= ndims(binImg) |
| 66 | + error('Input images must have same dimension'); |
| 67 | + end |
| 68 | + if any(size(refImg) ~= size(binImg)) |
| 69 | + error('Input images must have same size'); |
| 70 | + end |
| 71 | + |
| 72 | + ovr = overlay(refImg, binImg, color); |
| 73 | + name = 'NoName-ovr'; |
| 74 | + if ~isempty(refImg.Name) |
| 75 | + name = [refImg.Name '-ovr']; |
| 76 | + end |
| 77 | + ovr.Name = name; |
| 78 | + |
| 79 | + % add image to application, and create new display |
| 80 | + newDoc = addImageDocument(frame, ovr); |
| 81 | + |
| 82 | + % add history |
| 83 | + string = sprintf('%s = overlay(%s, %s, [%g %g %g]);\n', ... |
| 84 | + newDoc.Tag, refDoc.Tag, binDoc.Tag, color); |
| 85 | + addToHistory(frame, string); |
| 86 | + end |
| 87 | + |
| 88 | +end |
| 89 | + |
| 90 | +end % end classdef |
| 91 | + |
0 commit comments