MATLAB Answers

1

OOP - Sealed Superclasses

Asked by Peter Cook on 30 Jan 2018
Latest activity Commented on by Steven Lord
on 31 Jan 2018
I am trying to create a custom class to overload the MATLAB image object but am getting this error message:
Class 'matlab.graphics.primitive.Image' is Sealed and may not be used as a superclass
Is there a list of [graphics] objects in The MathWorks documentation which are not "sealed?"
Or should I start from the beginning with
classdef overloadedImage < handle

  0 Comments

Sign in to comment.

1 Answer

Steven Lord
Answer by Steven Lord
on 30 Jan 2018
 Accepted Answer

"Is there a list of [graphics] objects in The MathWorks documentation which are not "sealed?" "
No, there is no such list.
"I am trying to create a custom class to overload the MATLAB image object "
Can you say a little more about why you're trying to overload the image object? Perhaps you can already do what you want and you're just not aware of how to do it, or perhaps this could be worthy of an enhancement request?

  2 Comments

Peter Cook on 31 Jan 2018
Sure thing. For now, let's say I am really interested in creating a class that extends the image class that allows overloading of some basic operators.
classdef overloadedImage < matlab.graphics.primitive.image
For here & now, lets say I want to overload the plus and times multiplier.
I want to overload the plus operator to return a third overloaded image that is a merged superposition of the two images, with extra dimensions left transparent. (I am not sure if I want the overloadedImage object to keep all the original underlying data, if it should be a flattened copy of the the underlying data. My programming instinct is that the image that is displayed on the axes should be a flattened version but the object itself should store the underlying data somewhere off-screen).
Lets make hypothetical overloadedImage1 the classic cameraman.tif, and hypothetical overloadedImage2 a flipped and shifted cameraman.
overloadedImage3 = overloadedImage1 + overloadedImage2
would return
For the times operator
overloadedImage4 = 2*overloadedImage1 + 0.5*overloadedImage2;
would return
These sandbox exampled don't really cover some of the more difficult cases, like where the XData & YData of the underlying datasets dont overlap are are potentially sampled at different rates, in these cases the X&Y resampling would take place in the overloaded operator functions.
The application of this isn't image processing, but more for heatmap/waterfallmap type visualizations with datasets that have time and channel gaps. I was thinking that overloading would make manipulating and displaying these datasets easier/faster.
I was tinkering yesterday and determined 1 solution would just be to define a handle class and add as a property the handle to an image object (or objects), and in that sense sort of just be a "wrapper" class.
Steven Lord
on 31 Jan 2018
Do you need to have your class inherit from the Handle Graphics classes? From my quick reading of your description, I think having an object that contains the image data (the 2-D or 3-D array holding the values that represent the indexed, intensity, or truecolor image) would better suit your needs. That object could have overloaded methods that combine the data and then methods image, imagesc, etc. that call the appropriate Handle Graphics functions on the data stored in your objects.
Alternately, you could simply create functions to perform manipulation of the image data. Much of the functionality in Image Processing Toolbox is done by functions that accept plain numeric or logical arrays. For example, the A input argument for the imtranslate function is the "Image to be translated, specified as a nonsparse, numeric array of any class, except uint64 and int64, or a logical array."
Since you mentioned heatmaps and data gaps, there are a few functions that may be of use to you. First is the heatmap function introduced in release R2017a that can accept a table or timetable. There are functions that work on table arrays and/or timetable arrays to clean missing data. The retime function for timetable arrays may be of particular use for addressing time gaps.

Sign in to comment.