画像サイズと形式を指​定して保存する方法と​、コード内変数を変化​させて連番で画像を保​存する方法について

12 visualizaciones (últimos 30 días)
竜彦 今井
竜彦 今井 el 1 de Feb. de 2023
Comentada: Hiro Yoshino el 6 de Feb. de 2023
はじめまして、今井と申します。
Matlabは初心者のため、皆様のお知恵を拝借させていただきたく、投稿させていただきます。
現在、くさび形空気層による光の干渉縞画像の作製を検討しております。
さらに1枚ではなく、そのくさびの角度を変化させ、それに伴い干渉縞の間隔が徐々に広がっていく連番画像の取得が最終目的です。
調査した所、MATLAB用のマイケルソン干渉計シミュレーターのソースコードが公開されていたため、そちらを入手して試した所、1枚の干渉縞画像の表示に成功しました。
そちらのコードは以下添付してあるものです。
https://d-arora.github.io/Doing-Physics-With-Matlab/mpDocs/op_michelson.htm
% opMichB.m
% Michelson Interferometer
% Plane Wave illumination of mirrors
% Mirror M1I fixed precisely aligned at right angles to the beam
% Mirror M2 movable at tilt angle thetaX to beam
% Intensity is displayed on Detectoro screen due to the
% interference from the reflections from the two mirrors
% DOING PHYSICS WITH MATLAB:
% http://www.physics.usyd.edu.au/teach_res/mp/mphome.htm
% Documentation
% http://www.physics.usyd.edu.au/teach_res/mo/doc/op_michelson.htm
% Download Scripts
% http://www.physics.usyd.edu.au/teach_res/mp/mscripts/
% Ian Cooper email: matlabvisualphysics@gmail.com
% 190723 Matlab 2018b
clear
close all
clc
% SETUP ==============================================================
% Input wavelength [m] >>>
wL = 700e-9;
% Input Mirror separation distance >>>
dM = 1.85 * wL;
% Input X tilt angle thetaX w.r.t z axis [deg] (thetaX = 2*theta) >>>
thetaX = 30;
% Detector screen dimensions L [m]
L = 5e-6;
% Number of grid points
nD = 501;
% Propagation constant [1/m]
k = 2*pi/wL;
% Detector screen
xD = linspace(-L,L,nD);
yD = xD;
zD = 1;
% fringe spacing
dF = 1*wL/sind(thetaX);
% Electric field at Detector Screen
E1 = zeros(nD,nD);
E2 = E1;
for cx = 1: nD
E1(:,cx) = exp(1i*k*(zD + 2*dM));
E2(:,cx) = exp(1i*(k*zD*cosd(thetaX) + k*xD(cx)*sind(thetaX)));
end
Etot = E1 + E2;
% Detector screen intensity
SD = Etot .* conj(Etot);
SD = SD./max(max(SD));
% GRAPHICS =======================================================
figure(1)
pos = [0.1 0.1 0.25 0.75];
set(gcf,'Units','normalized')
set(gcf,'Position',pos)
set(gcf,'color','w')
subplot(3,1,1)
xP = 1e6.*xD; yP = 1e6.*yD;
pcolor(xP,yP,SD)
col = ColorCode(wL);
colorMap = [linspace(0,col(1),256)',linspace(0,col(2),256)',linspace(0,col(3),256)' ];
colormap(colorMap);
shading flat
xlim([-5,5])
set(gca,'fontsize',12)
axis off
subplot(3,1,2)
col = ColorCode(wL);
plot(xD.*1e6,SD(1,:),'color',col','linewidth',2)
xlim([-5,5])
set(gca,'xtick',-5:5)
grid on
set(gca,'fontsize',12)
xlabel('x_D [ \mum ]')
ylabel('Intensity S_D [ a.u. ]')
subplot(3,1,3)
xlim([0 100])
ylim([0 100])
h = 100; dh = -20;
text(0,h,'INPUTS','fontsize',12)
h = h+dh;
txt = sprintf(' wavelength \\lambda = %3.2f nm \n',wL*1e9);
text(2,h,txt,'fontsize',12)
h = h+dh;
txt = sprintf(' mirror separation distance \\Deltad = %3.2f nm \n',dM*1e9);
text(2,h,txt,'fontsize',12)
h = h+dh;
txt = sprintf(' X tilt angle 2\\theta = %3.2f deg \n',thetaX);
text(2,h,txt,'fontsize',12)
h = h+dh;
txt = sprintf('OUTPUTS');
text(2,h,txt,'fontsize',12)
h = h+dh;
txt = sprintf(' fringe spacing = %3.2f \\mum \n',dF*1e6) ;
text(2,h,txt,'fontsize',12)
text(90,-10,'opMichB.m','fontsize',8)
axis off
ここで質問なのですが、以下目標を達成するためには、どの様に手を加えればよろしいのでしょうか?
1.この回答のウインドウに表示された、赤と黒で示される干渉縞画像の部分のみを、jpeg形式で保存したい。
2.保存の際、解像度をフルHD(1920✕1080)にしたい
3.thetaXの値を○度から、✕度刻みに変化させながら合計△枚、1枚ずつ連番で保存させたい
それでは、よろしくお願いいたします。

Respuesta aceptada

Hiro Yoshino
Hiro Yoshino el 2 de Feb. de 2023
(1) 一番簡単な方法は、保存したいプロットにカーソルを合わせるとファイルに保存できるアイコンが出てくるのでそこから保存する。プログラミング的にやりたければ、
p1 = subplot(3,1,1);
xP = 1e6.*xD; yP = 1e6.*yD;
pcolor(xP,yP,SD)
col = ColorCode(wL);
.....
として、最終行あたりに以下を挿入して
exportgraphics(p1,"myImage.jpg");
で保存できます。
(2) exportgraphics のオプションで解像度は指定できます。Resolution (DPI) です。
こちらを参考にしてみてください。
(3) ループで走らせれば良いかと
thetaXarray = 30:0.5:90; % 30-90度で0.5刻み
for i = 1:length(thetaXarray)
thetaX = thetaXarray(i);
<<上記のコードをここに入れる>>
end
  3 comentarios
竜彦 今井
竜彦 今井 el 6 de Feb. de 2023
Hiro様、先日試してみたところ、無事に連番画像の出力に成功しました。
今後もMATLABの勉強に励みたいと思います。
また行き詰まった際には、ぜひご教授のほどよろしくお願いいたします。
Hiro Yoshino
Hiro Yoshino el 6 de Feb. de 2023
上手くいった様で良かったです。 私も昔、干渉縞と戦っていた時代があって懐かしく感じました

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2014b

Community Treasure Hunt

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

Start Hunting!