Importing an image into a figure - aliasing problem.

3 views (last 30 days)
I'm trying to import an image into a tiled figure, so I can compare it with some data. The imported image is clearly aliased.
I modified the image using Imagemagick (on Linux) to be 1920x300 pixels. The size of my graphics window is taken from my screen, and the saved png file is 2274x1382 pixels. I guess the aliasing comes when MATLAB stretches the image to fit the tile.
Is there a way I can include the image in the figure without aliasing? Maybe setting the size of that tile to be exactly 1920 pixels wide.
Original image:
Image saved by MATLAB:
This is (part of) my code:
tiledlayout( 'vertical', 'TileSpacing', 'none' );
nexttile;
heliImage = imread( fileHeliStack );
imshow(heliImage);
ylabel( 'Helicorders' );
nexttile;
plot( datimB42060, waveDirB42060, 'ro', 'MarkerSize', 5, 'MarkerFaceColor', 'r' );
ylim( [-90 270] );
xlim( tLimits );
datetick( 'x', 20, 'keepticks' );
xticklabels( [] );
ylabel( {'B42060', 'wave direction', '(degrees from N)'} );
ax = gca;
ax.XGrid = 'on';
nexttile;
plot( datimB42060, waveHeightB42060, 'ro', 'MarkerSize', 5, 'MarkerFaceColor', 'r' );
xlim( tLimits );
datetick( 'x', 20, 'keepticks' );
xlabel( 'UTC' );
ylabel( {'B42060', 'wave height', '(m)'} );
ax = gca;
ax.XGrid = 'on';
filePng = sprintf( "helistack_weather-%04d%02d%02d-%dd.png", yr, mo, da, ndays );
exportgraphics(gcf,filePng);

Answers (1)

Ayush
Ayush on 13 Mar 2024
Hey Dormant,
I understand that you are reading an image in MATLAB and the image is aliased and you want to know if you can fit the image in figure without aliasing.
To address the aliasing issue when displaying the image in MATLAB, you can control the size of the tile where the image is displayed to match the image's dimensions. This way, MATLAB won't need to stretch or shrink the image, which can introduce aliasing. Unfortunately, tiledlayout and nexttile don't offer direct control over the size of individual tiles. However, you can approximate a solution by manipulating the figure size and the tile aspect ratio to better match your image's dimensions.
Here's the code for the same:
% Assuming your screen DPI is 100 for conversion (adjust as necessary)
dpi = 100;
% Calculate figure size in inches
figWidth = 2274 / dpi; % width in inches
figHeight = 1382 / dpi; % height in inches
% Create figure with specified size
fig = figure('Units', 'inches', 'Position', [1, 1, figWidth, figHeight]);
% Use tiledlayout
tiledlayout('vertical', 'TileSpacing', 'none');
% Display the image in the first tile
nexttile;
heliImage = imread(fileHeliStack);
imshow(heliImage, 'InitialMagnification', 'fit'); % Try to prevent MATLAB from resizing
ylabel('Helicorders');
% Your plotting code for other tiles remains the same...
I hope this helps!

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!