To get a colormap from a JPEG file in MATLAB, you can follow these steps:
Read the JPEG file into MATLAB using the imread function. This will create a matrix containing the RGB values of each pixel in the image.
img = imread('your_image.jpg');
Convert the RGB image to indexed color using the rgb2ind function. This function will create an indexed image and a colormap. The indexed image will contain indices into the colormap for each pixel.
[ind_img, cmap] = rgb2ind(img);
Display the indexed image using the imagesc function. This will show you the color mapping that MATLAB has assigned to the image.
imagesc(ind_img); colormap(cmap);
The colormap can also be saved to a file using the imwrite function. For example:
imwrite(ind_img, cmap, 'your_colormap.png', 'png');
This will save the colormap as a PNG file, which you can open in any image viewer.