how are images stored in defaultimagecdata

1 view (last 30 days)
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
Umar
Umar on 27 Oct 2024
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
Walter Roberson
Walter Roberson on 26 Oct 2024
As I discussed, DefaultImageCData is double with all values above 1.0, and so imshow() will not display it properly with the default options.
Umar
Umar on 26 Oct 2024
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

Community Treasure Hunt

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

Start Hunting!