Why are plot titles assigned differently in Windows and MacOS?

조회 수: 4 (최근 30일)
Dennis Mueller
Dennis Mueller 2024년 10월 22일
편집: Bruno Luong 2024년 10월 22일
Hello,
the following behaviour has been observed running a script for demonstration of a simple iterative CT reconstruction:
In windows, all plot titles are displayed correctly. However, in macOS, some titles are assigned to the previous plot. This has been tested with two different machines (mac Studio and Macbook Air) in two different MATLAB versions (2024b, 2023b).
The behaviour should be reproducible with the following code (running here in browser creates the correct titles):
% Short demo script for iterative reconstruction of a ct image
clearvars;
close all;
ctImage= phantom('Modified Shepp-Logan',256);
figure()
imshow(ctImage)
title("Original Image")
sinogram = radon(ctImage);
[reconstructionLines, projectionAngles] = size(sinogram);
figure()
imshow(sinogram/max(sinogram, [], "all"))
title("Sinogram")
% Iterative reconstruction algorithm
numberOfReconstructionSteps = 180;
angleStepSize = 180/numberOfReconstructionSteps;
tempDifference = zeros(reconstructionLines, 1);
iterativeReconstruction = zeros(reconstructionLines, reconstructionLines);
for i = 1:reconstructionLines
iterativeReconstruction(i,:) = sinogram(i,angleStepSize)/reconstructionLines;
end
figure()
imshow(iterativeReconstruction/max(iterativeReconstruction, [], "all"))
title("First projection")
for i = 1:numberOfReconstructionSteps
iterativeReconstruction = imrotate(iterativeReconstruction, angleStepSize, "bicubic", "crop");
for j = 1:reconstructionLines
tempDifference(j) = sinogram(j,i) - sum(iterativeReconstruction(:,j));
iterativeReconstruction(:,j) = iterativeReconstruction(:,j) + tempDifference(j)/reconstructionLines;
end
figure(4)
imshow(iterativeReconstruction/max(iterativeReconstruction,[],"all"))
end
% Show result and compare to reconstruction by inverse radon transform
figure()
imshow(iterativeReconstruction)
title("Iterative reconstructed image")
reconstructedImage = iradon(sinogram, 0:179);
figure()
imshow(reconstructedImage/max(reconstructedImage, [], "all"))
title("Reconstruction by inverse Radon transform")
The titles i am getting in macOS are:
figure 1: correct title
figure 2: title of figure 3
figure 3 + 4 no title (4 has no title, 3 should have one)
figure 5: title of figure 6
figure 6: no title (there is no figure 7, which could be the title if there were more figures)

채택된 답변

Bruno Luong
Bruno Luong 2024년 10월 22일
편집: Bruno Luong 2024년 10월 22일
Regardless the platform, use graphic handles to be sure where the title (or any graphic object) correctly appears. As example
figh = figure();
axh = axes(figh);
imshow(axh, iterativeReconstruction)
title(axh, "Iterative reconstructed image")
  댓글 수: 2
Dennis Mueller
Dennis Mueller 2024년 10월 22일
Thanks, the suggestion with a small modification (see below) solved the issue.
figh = figure();
axh = axes(figh);
%imshow(axh, iterativeReconstruction)
imshow(iterativeReconstruction, 'Parent', axh)
title(axh, "Iterative reconstructed image")
Even though the problem is solved, i would still be interested in possible causes for the problem. The only other difference i observed was, that the script runs a lot faster on the apple machines (Which are also newer than the used windows laptop).
Bruno Luong
Bruno Luong 2024년 10월 22일
편집: Bruno Luong 2024년 10월 22일
My guess is that on Mac OS the creation of figure/axes are somewhat asynchronuous and the current object has not been updated internally when you inhvoke title, and it instead appears on an old axes

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by