stretching or compressing part of a matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammed Qahosh
el 19 de Oct. de 2023
Respondida: Sandeep Mishra
el 4 de Oct. de 2024
I have 400 by 400 pixels data set as in the attached txt file. When plotting it, the final figure is having a trapezoidal shape.
Is it possible in matlab to stretch the lower part of the figure or to compress the uppper part to have a square final shape.
Thanks for help.
1 comentario
Respuesta aceptada
Sandeep Mishra
el 4 de Oct. de 2024
Hi Mohammed,
I see that you are trying to modify a trapezoidal part of image into a square shape.
To achieve this, you can utilize the 'imresize' function to incrementally increase the width of the image. This process involves gradually scaling the top part with a smaller factor and the bottom part with a larger one.
Refer to the following code snippet:
% Reading the text file
M = readmatrix('Evsky.txt');
% Size of matrix
[rows, columns] = size(M);
% Scaling factors
topScale = 1.05;
bottomScale = 1.3;
% Initializing stretched image
stretchedImage = zeros(rows, columns * bottomScale);
% Scaling factors for each row
scalingFactors = linspace(topScale, bottomScale, rows);
for r = 1:rows
% new width for each row
newWidth = round(columns * scalingFactors(r));
% Resizing row
resizedRow = imresize(M(r, :), [1 newWidth]);
% Streching row
startIndex = round((columns * bottomScale - newWidth) / 2) + 1;
% Place the resized row in the new matrix
stretchedImage(r, startIndex:startIndex + newWidth - 1) = resizedRow;
end
% Stretched image
imshow(stretchedImage, []);
Please refer to the following MathWorks Documentation to learn more about ‘imresize’ function in MATLAB: https://www.mathworks.com/help/releases/R2024b/matlab/ref/imresize.html
I hope this helps you in resolving the query.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Elementary Math 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!