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

 Réponse acceptée

Steven Lord
Steven Lord le 30 Jan 2018

0 votes

"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?

4 commentaires

Peter Cook
Peter Cook le 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
Steven Lord le 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.
Steven Lord
Steven Lord le 29 Juin 2021
Since this question was asked, we added the capability to create your own chart classes. It may not meet all your needs, but take a look at this section of the documentation for more information.
Peter Cook
Peter Cook le 29 Juin 2021
@Steven Lord It has been quite some time since I asked this, and I haven't tried out any new MATLAB features. For the application for which this question/capability was relevant we had a number of axes containing heatmap-like data, timeseries data, and depth-series data. The data sources were independent of one another but the axes limits (e.g. depth/time) were bound to one another so that manipulation of one resulted in the need to resample the underlying datasets and re-display them in a "timely" manner (no perceptible latency). The image processing toolbox and MATLAB image object (imagesc unusable due to data gaps) were quite useful in the development phase. Ultimately we wound up with some lightweight MATLAB classes (each window pane essentially implementing a virtual class that contains some sort of dataset, has as a classmember an axes handle, and a method for drawing itself) that subscribed to change events on the x/y axes and wrote a bunch of C MEX Files to do the image manipulation. That code has been in production for a while but if we ever revisit it, I will be sure to evaluate the custom chart classes.

Connectez-vous pour commenter.

Plus de réponses (2)

Tibor Auer
Tibor Auer le 28 Juin 2021

0 votes

I have a similar issue with graph class, which is also Sealed. I would like to extend its funcionality by adding further methods and proprties.

4 commentaires

Tibor Auer
Tibor Auer le 28 Juin 2021
Modifié(e) : Tibor Auer le 28 Juin 2021
I have found a hacky workaround; however, it may not work for all cases:
classdef superClass
properties (Access = protected)
subClassInstance
end
methods
function obj = extendedGraph(varargin)
obj.subClassInstance = subClass(varargin{:});
end
function val = getSubClassProperty(obj,prop)
val = obj.subClassInstance.(prop);
end
function val = execSubClassMethod(obj,hMethod,varargin)
val = hMethod(obj.subClassInstance,varargin{:});
end
end
You can extend this class definition with custom properties and methods.
Steven Lord
Steven Lord le 29 Juin 2021
What types of methods and properties are you trying to add to the graph class?
Tibor Auer
Tibor Auer le 29 Juin 2021
The main extension is to add methods to calulate the line of the graph and some further methods supporting the calculation.
I have also added some customised plotting as a method, which also adapts to when the graph is a line of a graph.
Peter Cook
Peter Cook le 29 Juin 2021
@Tibor Auer I think your approach should work, but perhaps attempting to extend the builtin MATLAB graph class isn't wholly appropriate in this case because it looks like what you actually want is to modify hggraphics/plotting objects. MATLAB's graph object is used to describe/manipulate data that is defined by 2-tuples of vertices and edges (and other metadata). Maybe that's what you are actually doing here and I misunderstand your code sample.
Martin said a class should be "open for extension, but closed for modification" but that doesn't mean TMW has to listen to him :)

Connectez-vous pour commenter.

Tibor Auer
Tibor Auer le 29 Juin 2021

0 votes

@Peter Cook, There might be some misunderstanding. "Line of graph" is not about plotting but transforming: Line graph - Wikipedia

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by