Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 507277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:47:15+00:00 2026-05-13T06:47:15+00:00

I want to plot a line from one well-defined point to another and then

  • 0

I want to plot a line from one well-defined point to another and then turn it into an image matrix to use a Gaussian filter on it for smoothing. For this I use the functions line and getframe to plot a line and capture the figure window in an image, but getframe is very slow and not very reliable. I noticed that it does not capture anything when the computer is locked and I got an out of memory error after 170 executions.

My questions are:

  • Is there a substitute to getframe that I can use?
  • Is there a way to create the image matrix and draw the line directly in it?

Here is a minimal code sample:

figure1=line([30 35] ,[200 60]);
F= getframe;
hsize=40; sigma=20;
h = fspecial('gaussian',hsize,sigma); 
filteredImg = imfilter(double(F.cdata), h,256);
imshow(uint8(filteredImg));

[update]

High-Performance Mark’s idea with linspace looks very promising, but how do I access the matrix coordinates calculated with linspace? I tried the following code, but it does not work as I think it should. I assume it is a very simple and basic MATLAB thing, but I just can not wrap my head around it:

matrix=zeros(200,60);
diagonal=round([linspace(30,200,numSteps); linspace(35,60,numSteps)]);
matrix(diagonal(1,:), diagonal(2,:))=1;
imshow(matrix);
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:47:16+00:00Added an answer on May 13, 2026 at 6:47 am

    Here’s one example of drawing a line directly into a matrix. First, we’ll create a matrix of zeros for an empty image:

    mat = zeros(250, 250, 'uint8');  % A 250-by-250 matrix of type uint8
    

    Then, let’s say we want to draw a line running from (30, 35) to (200, 60). We’ll first compute how many pixels long the line will have to be:

    x = [30 200];  % x coordinates (running along matrix columns)
    y = [35 60];   % y coordinates (running along matrix rows)
    nPoints = max(abs(diff(x)), abs(diff(y)))+1;  % Number of points in line
    

    Next, we compute row and column indices for the line pixels using linspace, convert them from subscripted indices to linear indices using sub2ind, then use them to modify mat:

    rIndex = round(linspace(y(1), y(2), nPoints));  % Row indices
    cIndex = round(linspace(x(1), x(2), nPoints));  % Column indices
    index = sub2ind(size(mat), rIndex, cIndex);     % Linear indices
    mat(index) = 255;  % Set the line pixels to the max value of 255 for uint8 types
    

    You can then visualize the line and the filtered version with the following:

    subplot(1, 2, 1);
    image(mat);        % Show original line image
    colormap(gray);    % Change colormap
    title('Line');
    
    subplot(1, 2, 2);
    h = fspecial('gaussian', 20, 10);  % Create filter
    filteredImg = imfilter(mat, h);    % Filter image
    image(filteredImg);                % Show filtered line image
    title('Filtered line');
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a temp directory that will be unique to this build.
If all tables I want to delete from have the column gamer_id can i
I want the messagebox to only show if the number is equal to 0.
I want to get the header of a selected tab-item of a tab-control and
I want to have generalised email templates. Currently I have multiple email templates with
Every time that I want to do a Layout, I'm getting a black layout
I'm working on a project in C# w/ XNA, and I want to reorganize
I'm in the process of porting some code from Linux to Mac OS X.
I'm trying to build a Chrome browser extension, that should enhance the way the
I am using a 3rd-party rotator object, which is providing a smooth, random rotation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.