Text inside the meshgrid
Hello,
I am trying to place an arbitrary text inside the meshgrid. The code is as follows:
Nx = 201; Ny = 201;
TEXT = ‘K e k’; % Text to draw
FONT_SIZE = 10; % Font size
FONT_NAME = ‘Castellar’; % Font style (you can change this to any available font)
% Create a black image
img = zeros(Ny, Nx);
% Create a figure, axes, and an image object
figure(‘Visible’, ‘off’); % Create an invisible figure
axes(‘Units’, ‘pixels’, ‘Position’, [1, 1, Nx, Ny], ‘Visible’, ‘off’); % Create axes
imageHandle = imshow(img); % Show the black image
% Add text to the image
text(Nx / 2, Ny / 2, TEXT, ‘FontSize’, FONT_SIZE, ‘FontName’, FONT_NAME, …
‘Color’, [1, 1, 1], ‘HorizontalAlignment’, ‘center’, ‘VerticalAlignment’, ‘middle’);
% Get the image data
frame = getframe(gca);
imgWithText = frame.cdata;
% Convert to grayscale and then to binary mask
imgWithTextGray = rgb2gray(imgWithText);
mask = imgWithTextGray > 0;
% Invert the binary mask
mask_inverted = ~mask;
% Convert the inverted binary mask to double type
mask_double = double(mask_inverted);
% Flip upside down
obst = flipud(mask_double);
% Display the final mask (optional)
figure;
imshow(obst);
The code works fine with this grid resolution. However, when i increase the number of mesh points along y-axis (Ny), i get incorrect size of the obst. In particular, the maximum resolution of Ny is 420. For example, if i set Nx=601 and Ny=601, i will get the obst size of 420×601. Obviously, the problem is in this part:
% Get the image data
frame = getframe(gca);
imgWithText = frame.cdata;
I cannot understand why the frame data is limited along y-axis (Ny) by 420 points despite i have enough memory. Can someone suggest anything to fix this problem?
kind regards,
AlexHello,
I am trying to place an arbitrary text inside the meshgrid. The code is as follows:
Nx = 201; Ny = 201;
TEXT = ‘K e k’; % Text to draw
FONT_SIZE = 10; % Font size
FONT_NAME = ‘Castellar’; % Font style (you can change this to any available font)
% Create a black image
img = zeros(Ny, Nx);
% Create a figure, axes, and an image object
figure(‘Visible’, ‘off’); % Create an invisible figure
axes(‘Units’, ‘pixels’, ‘Position’, [1, 1, Nx, Ny], ‘Visible’, ‘off’); % Create axes
imageHandle = imshow(img); % Show the black image
% Add text to the image
text(Nx / 2, Ny / 2, TEXT, ‘FontSize’, FONT_SIZE, ‘FontName’, FONT_NAME, …
‘Color’, [1, 1, 1], ‘HorizontalAlignment’, ‘center’, ‘VerticalAlignment’, ‘middle’);
% Get the image data
frame = getframe(gca);
imgWithText = frame.cdata;
% Convert to grayscale and then to binary mask
imgWithTextGray = rgb2gray(imgWithText);
mask = imgWithTextGray > 0;
% Invert the binary mask
mask_inverted = ~mask;
% Convert the inverted binary mask to double type
mask_double = double(mask_inverted);
% Flip upside down
obst = flipud(mask_double);
% Display the final mask (optional)
figure;
imshow(obst);
The code works fine with this grid resolution. However, when i increase the number of mesh points along y-axis (Ny), i get incorrect size of the obst. In particular, the maximum resolution of Ny is 420. For example, if i set Nx=601 and Ny=601, i will get the obst size of 420×601. Obviously, the problem is in this part:
% Get the image data
frame = getframe(gca);
imgWithText = frame.cdata;
I cannot understand why the frame data is limited along y-axis (Ny) by 420 points despite i have enough memory. Can someone suggest anything to fix this problem?
kind regards,
Alex Hello,
I am trying to place an arbitrary text inside the meshgrid. The code is as follows:
Nx = 201; Ny = 201;
TEXT = ‘K e k’; % Text to draw
FONT_SIZE = 10; % Font size
FONT_NAME = ‘Castellar’; % Font style (you can change this to any available font)
% Create a black image
img = zeros(Ny, Nx);
% Create a figure, axes, and an image object
figure(‘Visible’, ‘off’); % Create an invisible figure
axes(‘Units’, ‘pixels’, ‘Position’, [1, 1, Nx, Ny], ‘Visible’, ‘off’); % Create axes
imageHandle = imshow(img); % Show the black image
% Add text to the image
text(Nx / 2, Ny / 2, TEXT, ‘FontSize’, FONT_SIZE, ‘FontName’, FONT_NAME, …
‘Color’, [1, 1, 1], ‘HorizontalAlignment’, ‘center’, ‘VerticalAlignment’, ‘middle’);
% Get the image data
frame = getframe(gca);
imgWithText = frame.cdata;
% Convert to grayscale and then to binary mask
imgWithTextGray = rgb2gray(imgWithText);
mask = imgWithTextGray > 0;
% Invert the binary mask
mask_inverted = ~mask;
% Convert the inverted binary mask to double type
mask_double = double(mask_inverted);
% Flip upside down
obst = flipud(mask_double);
% Display the final mask (optional)
figure;
imshow(obst);
The code works fine with this grid resolution. However, when i increase the number of mesh points along y-axis (Ny), i get incorrect size of the obst. In particular, the maximum resolution of Ny is 420. For example, if i set Nx=601 and Ny=601, i will get the obst size of 420×601. Obviously, the problem is in this part:
% Get the image data
frame = getframe(gca);
imgWithText = frame.cdata;
I cannot understand why the frame data is limited along y-axis (Ny) by 420 points despite i have enough memory. Can someone suggest anything to fix this problem?
kind regards,
Alex visualization, text MATLAB Answers — New Questions