how are images stored in defaultimagecdata

조회 수: 3 (최근 30일)
Kees
Kees 2024년 10월 24일
댓글: Umar 2024년 10월 27일
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?

채택된 답변

Kees
Kees 2024년 10월 26일
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
Umar
Umar 2024년 10월 27일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Umar
Umar 2024년 10월 24일

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 2024년 10월 25일
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
Walter Roberson
Walter Roberson 2024년 10월 26일
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 2024년 10월 26일
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.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by