How to create an image from a matrix (with floating point entries)

I have a 10 by 10 matrix (data by name). I am trying to create an image:

figure; (data); colormap(gray); 

The saved image is 560 * 420. How can I create a 10 by 10 image?

I also want to know how this works. First, it sets the -ve values ​​of the matrix elements to 0 , records> 1 - 1 , and then multiplies all records by 255 (for example, imwrite() )?

Is there any other function in MATLAB to directly convert from floating values ​​(without converting it to RGB, 0 <= value <= 1) to create an image?

+4
source share
2 answers

I am sure this has been asked before, but I cannot find a duplicate. You use the imagesc function to display the matrix as an image. So your code should look like this:

 figure; imagesc(data); colormap(gray); 

Color scaling is controlled by caxis , which takes arguments like caxis([cmin, cmax]) . From the docs:

caxis([cmin cmax]) sets the color limits for the given minimum and maximum values. Data values ​​less than cmin or greater than cmax mapped to cmin and cmax respectively. The values ​​between cmin and cmax linearly mapped to the current color palette.

So, in this case, the lowest value (if you did not set caxis ) will be displayed on the lowest color in the gray color range (white), and the maximum value will be set to black. To find out what RGB values ​​are used when adjusting the grayscale color scale, assign it to a variable and look at the values ​​(or write them down).

 gray=colormap('gray'); 

Also read the colormap documentation

+5
source

Perhaps you can find the "image" function from the Matlab Image Processing Toolkit related to what you want to do

As you can see, you can illustrate the matrix C by simply doing something like

 image(C) 

There is a second question about resizing an image.

 imresize(C) B = imresize(A, [numrows numcols]) 

which shows him how he works ,

With regard to the display method of any matrix, the image may be indexed or true. An indexed image stores colors as an array of indices in a color palette. Instead, the color values ​​for each pixel are stored directly as RGB triggers (R, G, B). Thus, any image can be called an array (m-by-n-by-3). This array consists of three m-on-n matrices (which are red, green, and blue color planes).

I believe the best way to find out how Matlab goes through its help and following the “Getting Started”

+2
source

All Articles