Why are logical arrays handled differently with the IMAGE function in MATLAB 6.5 (R13) than in previous versions?

1 view (last 30 days)
There are inconsistencies in the way logicals are treated in MATLAB 6.5 (R13). For example, if I have a 2D logical array, I would expect the image function to create a black and white image, as it did in previous versions of MATLAB:
testmat=(0.5<(rand(100,100)));
image(testmat);
Instead, the default HSV colormap is applied to the figure and the image colors are all in the blue color range.
If I use a 3D logical array, in previous versions I would get a black and white image. Now, I get an image that is all black. Setting the CData and CDataMapping properties has no effect on the image.
testmat=(0.5<(rand(100,100)));
mapmat = cat(3, testmat, testmat, testmat);
image(mapmat);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
This problem occurs because of the change in data types for logical arrays in MATLAB 6.5 (R13). Previously, the IMAGE function treated these arrays as doubles.
To work around the problem, try the following code:
% For 2D arrays, explicitly set the colormap of the figure:
testmat=(0.5<(rand(100,100)));
image(testmat);
colormap([0 0 0; 1 1 1]);
% For 3D arrays, you can convert the data to uint8:
mapmat = uint8(cat(3, testmat, testmat, testmat));
image(mapmat);

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!