how are images stored in defaultimagecdata

hello , i just started with matlab and i hope someone can assist me on this program:
defaultCData = get(0,'DefaultImageCData');
defImage = pow2(get(0,'DefaultImageCData'),47); % raised to the power 47 X = pow2(F,E) computes x = f * 2e
for shift = 10:63 %geeft aantal stappen aan, 63 is de hoogste max 63 images?
img = bitshift(defImage,shift);
imshow(img,'DisplayRange',[min(img(:))...
max(img(:))],'InitialMagnification',400)
title(num2str(shift));
pause(1)
end
i see what the pow2 , and bitshift command do, raise power and shift the bits...but is do not see how the different images are loaded, as i understand defaultimagecdata is a 64x64 matrix with different images , due to bitshift the different images are shown bij ' shifting' the colums to the left? And how can i load an individual columm / pictures if this is the case?

 Accepted Answer

Kees
Kees on 26 Oct 2024
thanx guys this explains a lot, the bitplanes explains it a bit further although it is still a bit difficult for me to picture this in 3d

1 Comment

Hi @Kees,
No problem. Please don’t forget to click “Accept Answer” and vote for @Walter Roberson for his efforts and contributions resolving your problem.

Sign in to comment.

More Answers (2)

Umar
Umar on 24 Oct 2024

Hi @Kees,

It is great to see your enthusiasm for learning. Let’s break down your code and clarify how it works, especially focusing on the manipulation of image data.

Default Image Data Retrieval

defaultCData = get(0,'DefaultImageCData');

This line retrieves the default color data for images in MATLAB, which is typically a 64x64 matrix. Each element in this matrix represents a pixel's color value.

Raising to a Power

defImage = pow2(get(0,'DefaultImageCData'),47);

Here, you are raising each element of the defaultCData matrix to the power of 47. The pow2 function computes ( x = f \times 2^e ), where f is the input matrix and e is the exponent. This operation significantly increases the values in the matrix, which may affect how the image is displayed.

Bit Shifting

for shift = 10:63
  img = bitshift(defImage, shift);
  imshow(img,'DisplayRange',[min(img(:)) 
  max(img(:))],'InitialMagnification',400)
  title(num2str(shift));
  pause(1)
end

In this loop, you are shifting the bits of the defImage matrix to the left by a specified number of positions (from 10 to 63). The bitshift function effectively multiplies the matrix by ( 2^{text{shift}} ), which can lead to a dramatic change in the pixel values, resulting in different visual representations of the image.

The bitshift function does not load different images per se; rather, it modifies the pixel values of the existing image matrix. Each iteration of the loop applies a different shift, which alters the brightness and contrast of the image displayed. The imshow function then visualizes this modified image. If you want to access individual columns of the defaultCData matrix, you can do so by indexing into the matrix. For example, to access the first column, you would use:

firstColumn = defaultCData(:, 1);

To display this column as an image, you can reshape it back to a 64x64 format if necessary, or simply display it directly if it represents a valid image format. Here’s how you might do that:

imshow(reshape(firstColumn, [64, 64]), 'InitialMagnification', 400);
title('First Column Image');

In nutshell, your code is effectively manipulating a single image matrix by altering its pixel values through bit shifting. Each shift results in a different visual representation of the same image. To access and display individual columns, you can index into the defaultCData matrix directly. Feel free to experiment with different shifts and explore how they affect the image.

If you have further questions or need clarification on specific points, don’t hesitate to ask!

Kees
Kees on 25 Oct 2024
i have added your line , however the colum is 1x64 so i gues it needs resising to 8x8?
firstColumn = defaultCData(:, 10);
imshow(reshape(firstColumn, [8, 8]), 'InitialMagnification', 400);
title('First Column Image');
...however with each value a change in the columm ,the picture stays the same: a white cube

5 Comments

You should expect the image to be all white when you do this.
defaultCData is datatype double, minimum value 3.61232107263537 .
When you imshow() something of datatype double, the assumption is that the data range is 0 to 1, and that anything below 0 is to be treated as the first color in the colormap and anything above 1 is to be treated as the last color in the colormap.
You can, for example,
imshow(reshape(firstColumn, [8, 8]), [], 'InitialMagnification', 400);
The [] signals that the data is to be rescaled between 0 and 1.
Note that
defaultCData = get(0,'DefaultImageCData');
Column10 = defaultCData(:, 10);
imshow(reshape(Column10, [8, 8]), [], 'InitialMagnification', 400);
title('Column 10 Image');
is not expected to produce a meaningful image.
DefaultImageCData is arranged so that bit planes are meaningful images; it is not arranged so that rows or columns are meaningful images.

Hi @Kees ,

To access individual columns of the defaultCData matrix, you can index into the matrix. For example, to access the 10th column:

firstColumn = defaultCData(:, 10);

However, as you noted, this column is a 1x64 vector. If you wish to reshape it into an 8x8 format, you can do so, but it is essential to ensure that the data is appropriate for such a transformation. Here’s how you can reshape and display it:

firstColumn = defaultCData(:, 10);
reshapedColumn = reshape(firstColumn, [8, 8]);
imshow(reshapedColumn, 'InitialMagnification', 400);
title('First Column Image');

Now you also mentioned based on your observation that the image remains unchanged, it is crucial to ensure that the data being reshaped is valid for display. If the column data does not represent a valid image format, the output will not change visually. Here’s an updated version of your code that includes reshaping and displaying the 10th column correctly:

% Retrieve default image color data
defaultCData = get(0, 'DefaultImageCData');
% Access the 10th column
firstColumn = defaultCData(:, 10);
% Reshape the column to 8x8
reshapedColumn = reshape(firstColumn, [8, 8]);
% Display the reshaped column
imshow(reshapedColumn, 'InitialMagnification', 400);
title('Reshaped 10th Column Image');

To access and display individual columns, you can index into the defaultCData matrix directly and reshape it as needed. Feel free to experiment with different columns and shifts to explore how they affect the image. I do agree with @Walter Roberson comments, “ DefaultImageCData is arranged so that bit planes are meaningful images; it is not arranged so that rows or columns are meaningful images.

If you still have any further questions or need clarification on specific points, please do not hesitate to ask!

As I discussed, DefaultImageCData is double with all values above 1.0, and so imshow() will not display it properly with the default options.
Hi @Walter Roberson,
Thank you for your feedback regarding the DefaultImageCData issue. I appreciate you bringing this to my attention. As always mentioned before your feedback is always valuable and always learn a lot from you.

Sign in to comment.

Products

Release

R2013b

Asked:

on 24 Oct 2024

Commented:

on 27 Oct 2024

Community Treasure Hunt

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

Start Hunting!