Get image handle with imshow

3 Ansichten (letzte 30 Tage)
Lask
Lask am 19 Okt. 2017
Bearbeitet: Stephen23 am 19 Okt. 2017
When I create a white image and try to access its handle via imshow, it returns a number instead of a struct.
% Create vector white image
img = 255 * ones(600, 600, 3, 'uint8');
% Get handle of the image
handle = imshow(img);
Typing 'handle' returns 174.0011 instead of a struct containing image properties. Why is this happening? I'm working with MATLAB 2014a
  2 Kommentare
Lask
Lask am 19 Okt. 2017
So how would I change the image data so I can transform it into a black image? I was using
handle.CData = zeros(600, 600, 3, 'uint8');
in MATLAB 2014b, but what's the way in 2014A?
Stephen23
Stephen23 am 19 Okt. 2017
Bearbeitet: Stephen23 am 19 Okt. 2017
Just like I wrote in my answer: use set and get to access or change the properties of any graphicsw object. Note that set and get work with all versions of MATLAB (with graphics handles).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 19 Okt. 2017
Bearbeitet: Stephen23 am 19 Okt. 2017
"Why is this happening?"
Because that is exactly what your version of MATLAB does. All graphics handles prior to R2014b are numeric values, so what you are seeing is entirely the expected behavior. You can access and change any properties using set and get. You can read about the changes introduced in R2014b here:
and in plenty of detail about the handles here:
and here:
Note that the blog also explains how numeric handles (pre-R2014b) work!
"... it returns a number instead of a struct."
Graphics handles R2014b and later are objects of a specific graphics class. They are not structs.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by