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

  • Home
  • SEARCH
  • 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 6666145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:47:52+00:00 2026-05-26T02:47:52+00:00

I’m writing a function file which is used to draw a line in an

  • 0

I’m writing a function file which is used to draw a line in an image. Now I’m facing the color issue. If I set color=[255 255 255] or color=[128 128 128] in the command window, the lines that appears in the image are both white.

For [128 128 128], it should be gray color, right? Which is not corresponding to the color table. I have tested some values for the color, the conclusion is that it takes any number greater than zero as 255. How do I fix this problem?

The following is my code.

function [ret]=drawline(p1,p2,color,img);
    xmax=size(img,1);
    ymax=size(img,2);
    if (p1(1)>xmax) || (p2(1)>xmax) || (p1(2)>ymax) || (p2(2)>ymax)
        error('value of point is ouside the image.');
    elseif (p1(1)==xmax) || (p2(1)==xmax) || (p1(2)==ymax) || (p2(2)==ymax)
        error('warning: value of point reach the max.');
    elseif (color(1)>256) ||(color(2)>256)||(color(3)>256)
        error('color value is out of range.');
    else
        m=(p2(2)-p1(2))/(p2(1)-p1(1));
        m=round(m);
        c=p1(2)-m*p1(1);
        for  x=linspace(p1(1),p2(1),1000)
            y=m*x+c;
            if p1(1)==p2(1)
               x=p1(1);
               y=p1(1):p2(2);
            end
            img(round(y),round(x),1)=color(1);
            img(round(y),round(x),2)=color(2);
            img(round(y),round(x),3)=color(3);
        end
    end
    ret=img
  • 1 1 Answer
  • 0 Views
  • 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-26T02:47:53+00:00Added an answer on May 26, 2026 at 2:47 am

    You might be using floating point images, where the color range is [0, 1] instead of [0, 255]. Perhaps the system is truncating all values over 1 instead of raising an error. I’m not matlab-savvy enough to correct your code, unfortunately.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

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.