How can I produce such an image?

조회 수: 1 (최근 30일)
Ahmad
Ahmad 2023년 3월 3일
댓글: DGM 2023년 3월 3일
I am a novice in posting questions in this site, so I apologize for any infringements which I might have made on question guidelines. I am trying to produce the above image with the help of imagesc() command and a matrix which according to my instructor is most trivial, however this triviality keeps escaping me. I tried Google Lens to find a similar image without success. Could anyone please drop a hint of this trivial matrix?

답변 (1개)

DGM
DGM 2023년 3월 3일
편집: DGM 2023년 3월 3일
When given a single-channel intensity image, imagesc() will render it in pseudocolor using the current axes colormap. Unless the color scaling limits are explicitly specified using caxis(), the global minimum of the image will correspond to the first color in the colormap, and the global maximum will correspond to the last index in the colormap.
For images, the origin is the northwest corner, so a linear NW-SE gradient is easy. The range of the image data isn't important, since it will be scaled anyway.
% you can use two orthogonal vectors and implicit expansion
x = linspace(0,1,100);
y = x.';
z = x + y;
imagesc(z) % display the image
colormap(jet(64)) % pick a colormap of a particular length
axis square % make sure it's displayed square
In this example, I'm using the standard jet() colormap, though the map used in your example image comes from somewhere else. I don't know if that's close enough for your needs. Otherwise, if you have a source for that particular map, you can use it in place of jet() in the call to colormap().
Alternatively, if your goal is to create a color raster image and save it to a file, you can do that too.
% same as before
x = linspace(0,1,100);
y = x.';
z = x + y;
N = 64; % number of quant levels
CT = jet(N); % the colortable
outpict = mat2gray(z); % normalize
outpict = ind2rgb(gray2ind(outpict,N),CT); % apply colormap
imwrite(outpict,'mypict.png') % save it
imshow(outpict) % or display it
In this case, the result is a 3-channel (RGB) image, which is displayed as-given by image()/imagesc()/imshow() without regard to the axes colormap. Unlike the prior example, the result can be saved or manipulated directly without needing to resort to figure capture.
  댓글 수: 1
DGM
DGM 2023년 3월 3일
If you want to replicate the given color table without having a means to generate it, you can use techniques like those described here:
In this case, I attached an approximate attempt as a function.
% same as before
x = linspace(0,1,100);
y = x.';
z = x + y;
imagesc(z) % display the image
colormap(myrainbowct(64)) % use the attached function
axis square % make sure it's displayed square

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

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by