Effacer les filtres
Effacer les filtres

How to set custom origin point?

67 vues (au cours des 30 derniers jours)
Elisa Lafforgue
Elisa Lafforgue le 22 Juin 2018
Commenté : Phong le 28 Mai 2023
Hello,
I can't manage to find any solution to this problem (do I have to precise I am a complete novice with matlab):
Lets say I have an image named "image" and I show it on screen with axis. By default, my axis will be, from one border to another, zero to end (number of the last column).
But I have a point in "image" that I want to be zero, the origin. I know that point from a mouse input. How do I explain to matlab that I want this point to be the origin of the axis?
Ps: does the following script do something good? (I found it in "How to change the default origin of the axis of rotation in 3d plot matlab") - I don't have matlab today to try that one... But I am not sure if it can even work with my problem.
origin = [13 58]
If you want some details about the contexte of this problem, here it is:
I am currently working in engineering and I have to do some experiments. In these experiments, I have to take two pictures of a burner: one with the burner cold and a graduated metal rod in it to make the mire (although I don't know if the term exist in english), the other picture is of the burner functionning. The mire help me to transform the image in matlab and know the distances, then I apply the same transformation in the second picture and I can have the flame length simply by mesuring from a point to another.To simplify the operation, I want the origin at the exit of the burner, so that I have directly the distance from the exit when I select a point on the flame. If I am not clear enough, let me know, please.
Thank you for your time and patience
E.L.

Réponse acceptée

Image Analyst
Image Analyst le 22 Juin 2018
Try this:
grayImage = imread('cameraman.tif');
[rows, columns, numberOfColorChannels] = size(grayImage);
origin = [13, 58]; % Assume x, y, NOT row, column
xdata = -origin(1) : columns - origin(1);
ydata = -origin(2) : columns - origin(2);
imshow(grayImage, 'XData', xdata, 'YData', ydata);
axis on;
hp = impixelinfo
grid on;
  2 commentaires
Elisa Lafforgue
Elisa Lafforgue le 26 Juin 2018
Thank you very much, it does work perfectly!
Phong
Phong le 28 Mai 2023
% I'm Nguyen Tien Phong, Hung Yen University of Technical Education
%This is an application program to plot multiple graphs on the same axes
%You guys edit it to be beautiful and suitable for multi-paragraph math problems
%Ngtienphong126@gmail.com
%Good luck
clear all
syms z
y1=3*z^3+2 % Ve tu 0 den 10 Plot this graph from 0 to 10; starting position is 0
y2=3*z^4+2*z^2+6 % Ve tu 10 den 25 (0-10-10-15) Plot this graph from 0 to 15; starting position is 10
L1=10
L2=15
Xtong=linspace(0,L1+L2,20) % Chia thanh 20 doan boi 20 diem de cbi ve cho tat ca
Yt=zeros(1,20)% Tao ra de ve cac diem chia tren z cua tat ca cac doan i
X2=linspace(0,L1,100); % Chia doan 1 thanh 100 diem de ve do thi cho doan 1
A2=subs(y1,z,X2) % Nhan gia tri tai 100 diem de ve do thi cho doan 1
plot(Xtong,Yt,'Linewidth',1) % X tong la tong chieu dai de xac dinh chieu dai truc Z khi ve
hold on
plot(X2,A2,'g','Linewidth',4) % Do thi doan 1
Xve2=linspace(10,25,100); % Chia thanh 100 diem cho doan i=2 tro di
XXX2=linspace(0,L2,100)
B2=subs( y2,z,XXX2) % Nhan 100 gia tri de ve duong do thi
plot(Xve2,B2,'r','Linewidth',4); % Ve do thi
xlabel('Duong truc Z');
title(['Bieu do Nz ', ': kN'])

Connectez-vous pour commenter.

Plus de réponses (2)

Elisa Lafforgue
Elisa Lafforgue le 22 Juin 2018
Thank you for your answer but with those code we have:
ax.YAxisLocation = 'origin'; % setting y axis location to origin
to set axis location to an automatic origin
Which you can change to put 'left', 'right', 'bottom'... but not a custom coordinates.
My problem is that I want to input some coordinates and make it be the new 'origin' of my axis. How can I do this?
  1 commentaire
KSSV
KSSV le 22 Juin 2018
How about using axis ?

Connectez-vous pour commenter.


Mark Saad
Mark Saad le 22 Juin 2018
Modifié(e) : Mark Saad le 22 Juin 2018
I was trying to do this the other day. I could not find anything, so I just manually shifted all of my data points. Let's say you have
x = [1 2 3 4];
y = [5 6 7 8];
and you want (1,5) to be the origin. Then just do
x = x - 1;
y = y - 5;
Above is an image of the original points on the left, and the points shifted so that (2,6) is the origin on the right.
  4 commentaires
Mark Saad
Mark Saad le 26 Juin 2018
I used the scatter function to plot the points alone.
% Set initial points.
x = [1 2 3 4];
y = [5 6 7 8];
% Plot initial points
subplot(1,2,1);
scatter(x,y,'r');
% Shift the points
x = x - 1;
y = y - 5;
% Plot the shifted points
subplot(1,2,2);
scatter(x,y,'b');
Elisa Lafforgue
Elisa Lafforgue le 27 Juin 2018
Thank you Mark Saad, it could be helpful some time.
Yes, Image Analyst, I have an image and not a plot. The answer provided just above by Mark Saad is interesting from my point of vu because I did not know we could such a thing and as I am trying to understand matlab better it is, indeed, very interesting.
Yet your answer was the best because it was exactly what I looked for and it work perfectly with my code.
The reason I picked the other answer instead is simple: I did not know what the "accept the answer" stood for... Actually I thought it was to make the answer seeable or to put an end to the thread as the answer was already given. And I cannot undo this apparently.
Sorry

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by