Skip to content

Commit

Permalink
better support of propagation of image name during processing
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Jan 5, 2021
1 parent a824220 commit d0943d5
Show file tree
Hide file tree
Showing 69 changed files with 362 additions and 131 deletions.
2 changes: 2 additions & 0 deletions src/@Image/Image.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
methods(Access = protected)

se = defaultStructuringElement(obj, varargin)

name = createNewName(obj, pattern)
end

%% Constructor declaration
Expand Down
5 changes: 3 additions & 2 deletions src/@Image/abs.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

% ------
% Author: David Legland
% e-mail: david.legland@inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2010-12-02, using Matlab 7.9.0.529 (R2009b)
% Copyright 2010 INRA - Cepia Software Platform.

res = Image('data', abs(obj.Data), 'parent', obj);
name = createNewName(obj, '%s-abs');
res = Image('Data', abs(obj.Data), 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/adjustDynamic.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
res = cast(res, outputClass);

% create resulting Image
res = Image('data', res, 'parent', obj);
name = createNewName(obj, '%s-adjDyn');
res = Image('Data', res, 'Parent', obj, 'Name', name);


function [mini, maxi] = computeExtremeValues(data) %#ok<DEFNU>
Expand Down
13 changes: 8 additions & 5 deletions src/@Image/angle.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function ang = angle(this)
%Returns the phase angles, in radians, of an image with complex elements.
function ang = angle(obj)
% Return the phase angles, in radians, of an image with complex elements.
%
% PHASE = angle(I)
%
Expand All @@ -15,7 +15,10 @@
% Created: 2017-09-29, using Matlab 9.3.0.713579 (R2017b)
% Copyright 2017 INRA - Cepia Software Platform.

real = getBuffer(channel(this, 1));
imag = getBuffer(channel(this, 2));
% retrieve components
imgA = channel(obj, 1);
imgB = channel(obj, 2);

ang = Image(atan2(imag, real));
% create result image
name = createNewName(obj, '%s-angle');
ang = Image('Data', atan2(imgA.Data, imgB.Data), 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/blackTopHat.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
dat = imbothat(obj.Data, varargin{1});

% create result image
res = Image('data', dat, 'parent', obj);
name = createNewName(obj, '%s-BTH');
res = Image('Data', dat, 'Parent', obj, 'Name', name);
6 changes: 5 additions & 1 deletion src/@Image/boundary.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@
%% Process

% erode the structure and compare with original
bnd = Image('data', op(obj.Data, se) ~= obj.Data, 'parent', obj);
newData = op(obj.Data, se) ~= obj.Data;

% create result image
name = createNewName(obj, '%s-bnd');
bnd = Image('Data', newData, 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/boxFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
end

% create result image
res = Image('data', data, 'parent', obj);
name = createNewName(obj, '%s-boxFilt');
res = Image('Data', data, 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/cat.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
data = cat(dim, data, var.Data);
end

res = Image('data', data, 'Parent', obj);
name = createNewName(obj, '%s-cat');
res = Image('data', data, 'Parent', obj, 'Name', name);
7 changes: 4 additions & 3 deletions src/@Image/circshift.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
% show(res)
%
% See also
%
% fftshift

% ------
% Author: David Legland
% e-mail: david.legland@inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2011-12-18, using Matlab 7.9.0.529 (R2009b)
% Copyright 2011 INRA - Cepia Software Platform.

% process data buffer, using Matlab Image processing Toolbox
data = circshift(obj.Data, varargin{:});

% create new image object for storing result
res = Image.create('data', data, 'parent', obj);
name = createNewName(obj, '%s-circshift');
res = Image('Data', data, 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/closing.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
data = imclose(getBuffer(obj), varargin{:});

% create new image object for storing result
res = Image(data, 'parent', obj);
name = createNewName(obj, '%s-clo');
res = Image(data, 'Parent', obj, 'Name', name);
11 changes: 4 additions & 7 deletions src/@Image/componentLabeling.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

% ------
% Author: David Legland
% e-mail: david.legland@inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2011-08-05, using Matlab 7.9.0.529 (R2009b)
% Copyright 2011 INRA - Cepia Software Platform.

Expand All @@ -40,11 +40,8 @@
end

% create new image
name = createNewName(obj, '%s-labels');
res = Image('Data', data, ...
'Parent', obj, ...
'Type', 'label');

% setup result image name
if ~isempty(obj.Name)
res.Name = sprintf('componentLabeling(%s)', obj.Name);
end
'Type', 'label', ...
'Name', name);
28 changes: 28 additions & 0 deletions src/@Image/createNewName.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function name = createNewName(obj, pattern)
% Create a new name from current image name and a string pattern.
%
% NAME = createNewName(IMG, PATTERN)
% Returns a new name, based on the following rule:
% * if image name is not empty, return sprintf(PATTERN, IMG.Name)
% * otherwise, return empty
%
% Example
% obj.Name = 'baseName';
% newName = createNewName(obj, '%s-processed');
% newName
% 'baseName-processed'
%
% See also
%

% ------
% Author: David Legland
% e-mail: [email protected]
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2021-01-05, using Matlab 9.8.0.1323502 (R2020a)
% Copyright 2021 INRAE.

name = '';
if ~isempty(obj.Name)
name = sprintf(pattern, obj.Name);
end
3 changes: 2 additions & 1 deletion src/@Image/crop.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
end

% create new image with cropped buffer
res = Image('data', obj.Data(indices{:}), 'parent', obj);
name = createNewName(obj, '%s-crop');
res = Image('Data', obj.Data(indices{:}), 'Parent', obj, 'Name', name);

% change origin of new image
res.Origin = newOrigin;
8 changes: 5 additions & 3 deletions src/@Image/ctranspose.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

% ------
% Author: David Legland
% e-mail: david.legland@inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2010-11-26, using Matlab 7.9.0.529 (R2009b)
% Copyright 2010 INRA - Cepia Software Platform.

Expand All @@ -26,6 +26,8 @@
end

% permute data array
dat = permute(obj.Data, [2 1 3:5]);
datz = permute(obj.Data, [2 1 3:5]);

res = Image('data', dat, 'parent', obj);
% create result image
name = createNewName(obj, 'transpose(%s)');
res = Image('Data', datz, 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/dilation.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
data = imdilate(getBuffer(obj), varargin{:});

% create new image object for storing result
res = Image(data, 'parent', obj);
name = createNewName(obj, '%s-dil');
res = Image(data, 'Parent', obj, 'Name', name);
6 changes: 3 additions & 3 deletions src/@Image/directionalFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@
end

% keep max or min along all directions
res = feval(op2, res, feval(op1, obj.Data, se));
res = feval(op2, res, feval(op1, obj.Data, se)); %#ok<FVAL>
end


%% create result image

res = Image('data', res, 'parent', obj);
name = createNewName(obj, '%s-dirFilt');
res = Image('Data', res, 'Parent', obj, 'Name', name);


function res = immean(img, filt, varargin)
Expand Down
15 changes: 6 additions & 9 deletions src/@Image/distanceMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@
% compute distance map
dist = bwdist(~obj.Data, varargin{:});

newName = '';
if ~isempty(obj.Name)
newName = sprintf('distanceMap(%s)', obj.Name);
end
newName = createNewName(obj, '%s-distMap');

% create new image
map = Image('data', dist, ...
'parent', obj, ...
'name', newName, ...
'type', 'intensity', ...
'channelNames', {'distance'});
map = Image('Data', dist, ...
'Parent', obj, ...
'Name', newName, ...
'Type', 'intensity', ...
'ChannelNames', {'distance'});
13 changes: 6 additions & 7 deletions src/@Image/double2rgb.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
% Example
% % Distance map of a binary image
% img = Image.read('circles.png');
% dist = distanceMap(img);
% dist = distanceMap(invert(img));
% dist(img) = NaN;
% rgb = double2rgb(dist, 'parula', [], 'w');
% show(rgb);
Expand Down Expand Up @@ -83,15 +83,14 @@
rgb(:,:,3,:) = b;
end

newName = '';
if ~isempty(obj.Name)
newName = sprintf('label2rgb(%s)', obj.Name);
end
% create result array
data = permute(rgb, [2 1 3 4:length(dim)]);

% create Image object from data
rgb = Image(permute(rgb, [2 1 3 4:length(dim)]), 'Type', 'color', ...
name = createNewName(obj, '%s-rgb');
rgb = Image(data, 'Type', 'color', ...
'Parent', obj, ...
'Name', newName);
'Name', name);

function color = parseColor(color)

Expand Down
3 changes: 2 additions & 1 deletion src/@Image/erosion.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
data = imerode(getBuffer(obj), varargin{:});

% create new image object for storing result
res = Image(data, 'parent', obj);
name = createNewName(obj, '%s-ero');
res = Image(data, 'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/exp.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

newData = exp(double(obj.Data));

res = Image('data', newData, 'parent', obj, 'type', 'intensity');
name = createNewName(obj, '%s-exp');
res = Image('Data', newData, 'Parent', obj, 'Type', 'Intensity', 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/extendedMaxima.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
data = imextendedmax(obj.Data, dyn, conn);

% create result image
res = Image('data', data, 'parent', obj, 'type', 'binary');
name = createNewName(obj, '%s-extMax');
res = Image('Data', data, 'Parent', obj, 'Type', 'binary', 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/extendedMinima.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
data = imextendedmin(obj.Data, dyn, conn);

% create result image
res = Image('data', data, 'parent', obj, 'type', 'binary');
name = createNewName(obj, '%s-extMin');
res = Image('Data', data, 'Parent', obj, 'Type', 'binary', 'Name', name);
5 changes: 3 additions & 2 deletions src/@Image/fillHoles.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

% ------
% Author: David Legland
% e-mail: david.legland@inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2011-09-11, using Matlab 7.9.0.529 (R2009b)
% Copyright 2011 INRA - Cepia Software Platform.

Expand All @@ -32,4 +32,5 @@
newData = imfill(obj.Data, conn, 'holes');

% create resulting image
res = Image('data', newData, 'parent', obj);
name = createNewName(obj, '%s-fillHoles');
res = Image('Data', newData, 'Parent', obj, 'Name', name);
5 changes: 3 additions & 2 deletions src/@Image/filter.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
h = double(h);

% create new image with result of filtering
name = createNewName(obj, '%s-filt');
res = Image(...
'data', imfilter(obj.Data, h, varargin{:}), ...
'parent', obj);
'Data', imfilter(obj.Data, h, varargin{:}), ...
'Parent', obj, 'Name', name);
3 changes: 2 additions & 1 deletion src/@Image/flip.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
end

% create empty result image
res = Image('data', flip(obj.Data, d), 'parent', obj);
name = createNewName(obj, '%s-flip');
res = Image('Data', flip(obj.Data, d), 'Parent', obj, 'Name', name);
11 changes: 6 additions & 5 deletions src/@Image/floodFill.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function res = floodFill(img, pos, value, varargin)
function res = floodFill(obj, pos, value, varargin)
% Flood-fill operation from a position.
%
% IMG2 = floodFill(IMG, POS, V)
Expand All @@ -24,22 +24,23 @@
% Copyright 2020 INRAE.

% check input dimensions
if size(pos, 2) ~= ndims(img)
if size(pos, 2) ~= ndims(obj)
error('Image:floodFill', ...
'position array size must match image dimension');
end

% create binary image of mask
pos = num2cell(pos);
mask = img == img.Data(pos{:});
mask = obj == obj.Data(pos{:});

% binary image for marker
marker = Image.false(size(img));
marker = Image.false(size(obj));
marker.Data(pos{:}) = true;

% compute the region composed of connected pixels with same value
rec = reconstruction(marker, mask);

% replace values in result image
res = Image(img);
name = createNewName(obj, '%s-floodFill');
res = Image(obj, 'Name', name);
res.Data(rec.Data) = value;
3 changes: 2 additions & 1 deletion src/@Image/geodesicDistanceMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,5 @@
dist(mask > 0) = dist(mask > 0) / w1;
end

dist = Image('Data', dist, 'Parent', mask, 'Type', 'Intensity');
name = createNewName(mask, '%s-geodDistMap');
dist = Image('Data', dist, 'Parent', mask, 'Type', 'Intensity', 'Name', name);
Loading

0 comments on commit d0943d5

Please sign in to comment.