I`m trying to plot a data represents by points and display an image in the background of the graphics. But it change the color and the position of the image (the image is white, matlab is change for yellow).
I tried [X,cmap], but I also need adapt the size of the image to chart scale.
clc;
clear all;
velocidade_gas = [1.40 1.3896 1.3879 1.3843];
velocidade_liquido = [2.427 3.230 4.180 4.919];
loglog(velocidade_gas,velocidade_liquido,'s','MarkerFaceColor',[0 0.447 0.741]);
xlabel('Velocidade Supeficial do Gás (m/s)');
ylabel('Velocidade Superficial do Líquido (m/s)');
title('Pontos Gerados no Mapa de Mandhane');
axis([0.1 500 0.01 20]);
hold on
[X, cmap] = imread('mandhane.jpeg');
image(xlim, ylim, [X, cmap]);
mapa = uistack(X,'bottom');

답변 (1개)

DGM
DGM 2022년 4월 27일
편집: DGM 2022년 4월 27일

1 개 추천

I'm not sure why the image is upside-down, but the reason it's yellow is probably because it's a monochrome (single-channel) image. When you give image() a single-channel image, it applies the current colormap to it (probably parula() in this case).
If so, the fix is simple.
X = imread('mandhane.jpeg');
image(xlim, ylim,repmat(X,[1 1 3]));
This simply replicates the single-channel image into a 3-channel image -- which image() will treat as an RGB image instead of colormapping it.
That's just my current estimation. It'd help to see the actual image to be sure what's going on.
If you're doing a bunch of fancy stuff with your axes setup that's causing the image to be shown upside-down, you can always just flip it before displaying
X = flipud(X);

댓글 수: 2

Thank you! It workss! But now, I got another problem... The image is hiding my data points and uistack isn't working as it should. Here is the image
Oh I should've noticed that.
You need to be using the handle to the image() object, not the actual picture itself when you use uistack(). If you're trying to get the diagram to actually align with the axes, you'll have to prepare the image to match. It would probably be cleaner to replicate the diagram entirely, but that might be more work.
velocidade_gas = [1.40 1.3896 1.3879 1.3843];
velocidade_liquido = [2.427 3.230 4.180 4.919];
loglog(velocidade_gas,velocidade_liquido,'s','MarkerFaceColor',[0 0.447 0.741]);
xlabel('Velocidade Supeficial do Gás (m/s)');
ylabel('Velocidade Superficial do Líquido (m/s)');
title('Pontos Gerados no Mapa de Mandhane');
axis([0.1 500 0.01 20]);
hold on
% get image
X = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/980705/image.jpeg');
% correct for distortion
% these are the box corners
boxm = [73 19; % [x y]
74 536;
634 532;
636 19];
% assert that this is where they're supposed to be
boxf = [74 19; % [x y]
74 535;
635 535;
635 19];
TF = fitgeotrans(boxm,boxf,'projective');
outview = imref2d(size(X));
X = imwarp(X,TF,'fillvalues',255,'outputview',outview);
% crop to box extents
X = imcrop(X,[73 19 561 515]);
% flip image
X = flipud(X);
% display image
hi = image(xlim, ylim,repmat(X,[1 1 3]));
uistack(hi,'bottom')

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

카테고리

도움말 센터File Exchange에서 Display Image에 대해 자세히 알아보기

제품

댓글:

DGM
2022년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by