Plotting pcolor plot on an image at a particular area.

조회 수: 7 (최근 30일)
waqas
waqas 2019년 10월 1일
댓글: waqas 2019년 10월 9일
Hi,
I have done some analysis on a particular region of an image which I now want to plot on the over the image. Following image is an example of what I am trying to get as output ( In my case it is a complete pacman shape but some region would be removed because of NaNs):
Now, I can plot the pcolor of the colored region separatly but am unable to get it with image. Colorbar changes to the gray values. Attached is the relevant binary matrix (region) which shows the region where the profile should be as well as image (img) which is suppose to be in the background and (out) is the values in the disc region.
  댓글 수: 2
Mahesh Taparia
Mahesh Taparia 2019년 10월 4일
Hi,
It is not clear what you want to do with the 3 images you have attached. Can you explain clearly?
waqas
waqas 2019년 10월 4일
Hi Mahesh,
"region" is just a mask of the area in the image "img" over which I am trying to plot pcolor of the third variable. So idea is to plot the gray image in the background and then have pcolor plot over it. I hope this clearifies the statement. End result would be similar to something like the attached image with the question statement.

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 8일
pcolor() accepts x and y arguments as well as the data, so to plot it on top of something else, plot the other things first, "hold on", then pcolor() passing in appropriate coordinates.
pcolor() is, by the way, surf() followed by view(2) internally, except that pcolor() does not accept all of the options that surf() accepts.
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 10월 8일
All items on the same axes share the same colormap.
You can create multiple axes in the same place and have one colormap for each. If you do that, make sure that the background color of the top axes is set to 'none' .
However, the better approach is to convert the grayscale image to RGB so that it does not require a colormap. You can do that by using
rgb_version = repmat(YourGrayImage, 1, 1, 3);
waqas
waqas 2019년 10월 9일
Thank you for the suggestion. It was much simpler approach and did the job perfectly.
Cheers,

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

추가 답변 (1개)

darova
darova 2019년 10월 4일
You can just merge images
clc,clear
load matlab.mat
[m,n] = size(img);
[X,Y] = ndgrid(1:m,1:n);
Z = (X.*Y).*region; % try (X+Y)
Z = Z/max(Z(:)); % just scale 0 .. 1
% make RGB image: RED - 1, GREEN - changes, BLUE - 0
% result: red to orange
I1 = cat(3,Z*0+1,Z,Z*0);
mask = repmat(region,[1 1 3]);
I2 = double( repmat(img,[1 1 3]) );
I2 = I2/max(I2(:)); % scale 0 .. 1
I = I1 .* mask + I2 .* ~mask; % merge images
imshow(I);
cm = flipud(autumn);
colormap(cm)
h = colorbar;
  댓글 수: 20
waqas
waqas 2019년 10월 8일
I tried that but now the spacing between the figures is all messed up and apparently title xlabel etc are not working either. With tight_subplot, i can control the spacings too.
darova
darova 2019년 10월 8일
You can hide ticks
set(ax2,'xtick',[])
set(ax2,'xticklabel',[])

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

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by