이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
overlay plot on imgage
조회 수: 110 (최근 30일)
이전 댓글 표시
채택된 답변
Cedric
2017년 10월 2일
편집: Cedric
2017년 10월 2일
hold on
for overlays, for example:
imshow( myImage ) ;
hold on ;
plot( x, y, 'rx' ) ;
and you will see the plot over the image. You can have more control by creating axes by yourself, but it is more complicated. For this, if you really have the time to learn, look at my answer here.
댓글 수: 13
Don
2017년 10월 4일
Thank you for your help so far. I am struggling with the code you supplied for the other answer, still haven't got it (yet)
Don
2017년 10월 5일
편집: Cedric
2017년 10월 5일
OK.. Here's what I have so far:
Figure(2)
disp (' get image that goes with the data file');
These are all images of different sizes. Are pictures of famous paintings
[filename, filepath] = uigetfile('*.jpg', 'Select ejpg file');
pict = cat(2,filepath,filename);
[X,map] = imread(pict);
figure('position', [1, 10,10,10]);
I doubt this statement is necessary or useful. I think I want to fix the image to standard size
hold on;
figure(3);
positiveXaxisMask = xaxis >0 & xaxis < 1 & yaxis >0 & yaxis <1;
this stuff plots eye fixations from a data set
plot(xaxis(positiveXaxisMask), yaxis(positiveXaxisMask),'color','r','marker','o','LineStyle','--');
axis([0 1 0 1]);
x0 = 300; % seet size of plot
y0 = 75;
width = 675;
height = 675;
set(gcf,'units','points','position',[x0,y0,width,height])
% axis([0,1,0,1]);
xlabel(' Left<--- ---> Right');
ylabel('Bottom <-- --> Top')
TitleText=cat(2,'XY Coordinates of Fixation ',name);
title (TitleText);
TrackerData = cat(2,name,'.png');
eventually save the result
TrackerData = cat(2, PathName,TrackerData);
saveas(gcf,TrackerData); % save plot to subj direcory
Many thanks for any help you can give Don
Cedric
2017년 10월 5일
편집: Cedric
2017년 10월 5일
You have to try little bit by little bit. First with
figure('position', [1, 10,10,10]);
hold on;
figure(3);
you create a tiny figure in the lower-left corner of your screen, then you tell MATALB not to overwrite its content but to overlay whatever will be plotted next, then you create a new figure. What is the purpose of the first?
I'd say, forget about all the code for user management, scaling, etc, at first and work with a static image, e.g. the MonaLisa attached.
So first, are we able to create a empty large figure?
figure() ;
well, it's a new empty figure but not that large. Can we set its position/size relative (normalized) to the screen?
set( gcf, 'Units', 'normalize', 'Position', [0.1,0.1,0.8,0.7] ) ;
where the vector of positions is [x,y,w,h] given as a fraction of the screen size (so x=10%, y=10%, w=80%, h=70%).
Great, first part is working and it is two lines long. Then, are we able to plot something? Let's try a sine wave, just for the test:
x = 1 : size(img, 2) ; % 1 pixel to the width of the image.
y = size( img, 1 ) * (sin(x/50)+1) / 2 ; % Scale a sine to the height of the image.
If we plot it in the current figure, it will clear the previous content first, unless we tell MATLAB that it must "hold" the previous content and overlay the new:
hold( 'on' ) ;
plot( x, y, 'b' ) ;
That seems to work too:
(sorry for the sacrilege by the way ;))
So now we know how to plot, overlay curves, and we can "complexify" the code a little by working on the curves that you need to plot.
I let you check if this works for you and try the next steps, always making small steps.
Don
2017년 10월 5일
편집: Cedric
2017년 10월 5일
figure(3);
disp (' get image that goes with the data file');
[filename, filepath] = uigetfile('.jpg', 'Select .jpg file');
pict = cat(2,filepath,filename);
img=set( gcf, 'Units', 'normalize', 'Position', [0.1,0.1,0.8,0.7] ) ;
imshow(pict)
x = 1 : size(img, 2) ; % 1 pixel to the width of the image.
y = size( img, 1 ) * (sin(x/50)+1) / 2 ; % Scale a sine to the height of the image.
hold( 'on' ) ;
plot( x, y, 'r' ) ;
I got the image to plot and (I guess) the right dimensions on the screen. BUT -- no superimposed plot. Note: Had to add the definition of img had to add imshow
x and y both have value 1×0 empty double row vector
Cedric -- thanks very much for your help on this
Cedric
2017년 10월 5일
편집: Cedric
2017년 10월 5일
No problem, see my example, I never wrote "img=set(...".
Also, using FULLFILE is better for concatenating parts of a path to a file, and you should name variables according to what they store. If you look at the output of UIGETFILE, you will see that the two parameters are strings: the base path and the file name.
I realize that I forgot to copy the part about loading the image in my example, my mistake!
[filename, filepath] = uigetfile( '.jpg', 'Select .jpg file' ) ;
imgLocator = fullfile( filepath, filename ) ;
figure() ;
set( gcf, 'Units', 'normalize', 'Position', [0.1,0.1,0.8,0.7] ) ;
img = imread( imgLocator ) ;
imshow( img ) ;
hold( 'on' ) ;
x = 1 : size(img, 2) ; % Pixel 1 to the width of the image.
y = size(img, 1) * (sin(x/50)+1) / 2 ; % Scale a sine to the height of the image.
plot( x, y, 'r', 'LineWidth', 3 ) ;
Don
2017년 10월 6일
편집: Cedric
2017년 10월 6일
The code you sent works GREAT for plotting sine wave over any of my pictures
figure(3);
set( gcf, 'Units', 'normalize', 'Position', [0.1,0.1,0.8,0.7] ) ;
img = imread(imgLocator) ;
imshow(img) ;
hold( 'on' ) ;
x = 1 : size(img, 2) ; % Pixel 1 to the width of the image.
y = size(img, 1) * (sin(x/50)+1) / 2 ; % Scale a sine to the height of the image.
plot( x, y, 'r', 'LineWidth', 3 ) ;
BUT, getting this data to plot over the picture is non trivial for me. This code gets the plot shown below
figure(2);
positiveXaxisMask = xaxis >0 & xaxis < 1 & yaxis >0 & yaxis <1;
plot(xaxis(positiveXaxisMask), yaxis(positiveXaxisMask),'color','r','marker','o','LineStyle','--');
x0 = 300; % set size of plot
y0 = 75;
width = 675;
height = 675;
set(gcf,'units','points','position',[x0,y0,width,height])
xlabel(' Left<--- ---> Right');
ylabel('Bottom <-- --> Top')
TitleText=cat(2,'XY Coordinates of Fixation ',name);
title (TitleText);
Ive tried substituting xaxis,yxais but to no avail. plot( xaxis, yaxis, 'r', 'LineWidth', 3 ) ;
Sorry to be so dense about this, But were VERY CLOSE to a solution!
Cedric
2017년 10월 6일
I don't understand why you have these figure(2) and figure(3). In figure #3 you seem to display an image
set( gcf, 'Units', 'normalize', 'Position', [0.1,0.1,0.8,0.7] ) ;
img = imread(imgLocator) ;
imshow(img) ;
then configure the axes switching the hold on:
hold( 'on' ) ;
and then overlay whatever curves you have defined in vectors x and y.
But in figure #2 I don't see where you add the image before plotting your points.
Don
2017년 10월 6일
well, the figure 2 is a separate plot so I can see that something is happening I hope it is independent of figure 3. Figure 3 works great except for the data points. Once 3 works, I can get rid of 2
As for figure 3, I don't know how to add the extra data points. So figure 2 is presented to you so you can see what I do to the get the data points. But I really want the data points added to figure 3
sorry for any confusion
Cedric
2017년 10월 6일
Ok, I think that I understand now. You should rescale your x and y variables to the width and height of the image if they are relative and in [0,1], and not try to rescale the image or the axes or the figure.
I don't understand what you are doing by using this mask on your data points if they are already in [0,1]. If not, how to you define them?
Say you have xPoints and yPoints the coordinates of your points relative to the image size (in [0,1]), you can do this:
imgLocator = ... ;
xPoints = ... ;
yPoints = ... ;
% - Create figure.
figure() ;
set( gcf, 'Units', 'normalize', 'Position', [0.1,0.1,0.8,0.7] ) ;
% - Display image.
img = imread( imgLocator ) ;
imshow( img ) ;
% - Rescale x,y in [0,1] to image width,height.
x = size( img, 2 ) * xPoints ;
y = size( img, 1 ) * yPoints ; % or (1-yPoints) depending the direction.
% - Overlay points to image.
hold( 'on' ) ;
plot( x, y, 'ro', 'MarkerSize', 10, 'LineWidth', 3 ) ;
Don
2017년 10월 7일
sorry to quibble .... imgLocator = ... ; xPoints = ... ; yPoints = ... ;
xPoints gives me the error message Error: The expression to the left of the equals sign is not a valid target for an assignment.
I can't find a definition or explanation of "...", but I think somehow it initiates something in the imgLocator line that is not finished by the xPoints line. I've looked everywhere but can't find an discussion of it
Don
2017년 10월 7일
YAY! I think I got it -- imgLocator = fullfile(filepath, filename) ;, xPoints = xaxis; yPoints = yaxis;
This seems to work! You are a genius. Thank you Thank you Thank you
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)