File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,12 @@ function copyFields(obj, that)
283
283
if ~isempty(that .UnitName )
284
284
obj.UnitName = that .UnitName ;
285
285
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
+
286
292
if ~isempty(that .AxisNames )
287
293
obj .AxisNames(1 : nd ) = that .AxisNames(1 : nd );
288
294
end
Original file line number Diff line number Diff line change @@ -25,3 +25,15 @@ function test_2d(testCase) %#ok<*DEFNU>
25
25
img2 = img .crop([51 200 51 150 ]);
26
26
27
27
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 );
You can’t perform that action at this time.
0 commit comments