Why are plot titles assigned differently in Windows and MacOS?

2 visualizaciones (últimos 30 días)
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)

Respuesta aceptada

Bruno Luong
Bruno Luong el 22 de Oct. de 2024
Editada: Bruno Luong el 22 de Oct. de 2024
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 comentarios
Dennis Mueller
Dennis Mueller el 22 de Oct. de 2024
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 el 22 de Oct. de 2024
Editada: Bruno Luong el 22 de Oct. de 2024
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by