Skip to content

Commit e976afd

Browse files
committed
propagates channel names when creating new image from parent
1 parent 52a9b80 commit e976afd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/@Image/Image.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ function copyFields(obj, that)
283283
if ~isempty(that.UnitName)
284284
obj.UnitName = that.UnitName;
285285
end
286+
287+
% copy channel names if images have same number of channels
288+
if size(obj.Data,4) == size(that.Data,4) && ~isempty(that.ChannelNames)
289+
obj.ChannelNames = that.ChannelNames;
290+
end
291+
286292
if ~isempty(that.AxisNames)
287293
obj.AxisNames(1:nd) = that.AxisNames(1:nd);
288294
end

tests/image/test_crop.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ function test_2d(testCase) %#ok<*DEFNU>
2525
img2 = img.crop([51 200 51 150]);
2626

2727
assertEqual(testCase, [150 100], size(img2));
28+
29+
30+
function test_keepChannelNames(testCase) %#ok<*DEFNU>
31+
32+
img = Image.read('peppers.png');
33+
clearCalibration(img);
34+
img.ChannelNames = {'Rot', 'Gruen', 'Blau'};
35+
36+
img2 = img.crop([51 200 51 150]);
37+
38+
assertEqual(testCase, [150 100], size(img2));
39+
assertEqual(testCase, img2.ChannelNames, img.ChannelNames);

0 commit comments

Comments
 (0)