Part of FRC and design/engineering is perseverance. Keep your chin up, your thoughts positive, and have respect for your work and the work of your teammates. - Nathan_Fraser [more]
 Chief Delphi incorrect subtraction in get color pixel value
 Team 51 CD-Events CD-Media CD-Swap CD-Spy FRC-Spy Unsung FIRST Heroes WFA
The Chief Delphi Forums are sponsored by Innovation First International, Inc.

#1
04-06-2012, 02:43 PM
 tilky Registered User AKA: Ryan Thielke FRC #3137 Team Role: Programmer Join Date: Nov 2011 Rookie Year: 2011 Location: Connetquot Posts: 177
incorrect subtraction in get color pixel value

for whatever reason, when i get the color pixel value of a pixel and convert it to rgb, if i subtract 20 from it, it comes out to some strange number (247 for what i was doing). I finally figured out that you need to convert the red green and blue values to singles in order to be able to do any math on the numbers and get the right answer. Does anyone have an explanation of this?
#2
04-07-2012, 03:52 PM
 Greg McKaskle Registered User no team (Team NI) Join Date: Apr 2008 Rookie Year: 2008 Location: Austin, TX Posts: 3,388
Re: incorrect subtraction in get color pixel value

I suspect that the math is being done with an unsigned 8 bit integer. In that system, 0 - 1 is equal to 255. Strange, and that is why integers are a bit of a risky tradeoff. To check this, do the math as normal, then add or subtract 256 to the number to get it back into the range of 0 to 255. That is the result that you will get with unsigned numbers.

#3
04-08-2012, 06:16 AM
 tilky Registered User AKA: Ryan Thielke FRC #3137 Team Role: Programmer Join Date: Nov 2011 Rookie Year: 2011 Location: Connetquot Posts: 177
Re: incorrect subtraction in get color pixel value

thats really weird that it would do that. do you have an explanation as to why this happens, or do you just know that it does.
#4
04-08-2012, 06:58 AM
 Mark McLeod Itinerant Programmer AKA: Hey dad...Father...MARK FRC #0358 (Robotic Eagles) Team Role: Engineer Join Date: Mar 2003 Rookie Year: 2002 Location: Hauppauge, Long Island, NY Posts: 6,798
Re: incorrect subtraction in get color pixel value

That's normal computer science
It makes sense once you begin thinking of each data type as the bits it is capable of storing, rather than the everyday math you are accustom to.

Each data type has it's own unique data representation and we have to understand what each of them means and how it affects the values we are storing in it and how the data types affect any calculations or intermediate calculations that we may go through.

If you use a data type that can only hold 0-255, then what would you expect to happen when adding or subtracting leaves us with a number outside the possible range? If you look in the LabVIEW palettes you'll find a dozen different data types you can use. Understanding why you would use each of them is one of those skills we develop.

Integer (computer science): http://en.wikipedia.org/wiki/Integer_%28computer_science%29
Signed number representations: http://en.wikipedia.org/wiki/Signed_...epresentations
__________________
"Always exaggerate. It makes life seem more interesting." - Robert Weber

Last edited by Mark McLeod : 04-08-2012 at 07:04 AM.
#5
04-09-2012, 09:40 AM
 Greg McKaskle Registered User no team (Team NI) Join Date: Apr 2008 Rookie Year: 2008 Location: Austin, TX Posts: 3,388
Re: incorrect subtraction in get color pixel value

Welcome to the matrix.

Since computers are typically expected to be really fast, they take lots of shortcuts. They take advantage of not doing the things that people aren't looking at, etc. They are just as capable of being careful and accurate, but that is a tradeoff, and most people prefer their video fast instead of accurate.

What you are discovering in this instance, is that it is common for images to be saved with one byte for red, green, and blue. One byte can only hold 256 unique values, so the computer scientists decided to use them as an unsigned integers. Integers are specialized and can only store the a fixed set of values. Booleans can only store two value, bytes 256, shorts can store 65536, and longs can only store a measly 4 billion values. All of these share a similar discrete mathematical system that defines the results of addition, subtraction, multiplication, and other operations.

Is the result correct? It works as intended, but not the same as a calculator. That tradeoff allows it to do specialized work quickly. Can you figure out how to get the answer you wanted? Or can you describe what answer you wanted?

#6
04-09-2012, 06:42 PM
 tilky Registered User AKA: Ryan Thielke FRC #3137 Team Role: Programmer Join Date: Nov 2011 Rookie Year: 2011 Location: Connetquot Posts: 177
Re: incorrect subtraction in get color pixel value

i figured out how to fix it by converting them to singles, which would make sure they are the same

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase     Moderated Discussion Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         WindRiver C++         Java         MATLAB & Simulink         Python     intelitek easyC/REC information         easyC v2 for Vex         easyC for FRC         REC/Learnmate         WPILib         easyC PRO     Control System         IFI Control System         FRC Control System         Sensors         USB Chicklet     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Pro ENGINEER / Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     FIRST in Michigan     Mid-Atlantic Robotics     Off-Season Events         Chief Delphi Invitational     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Unsung FIRST Heroes     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Robot Chicks Union (RCU)         Southern California Regional Robotics Forum         Hearing-Impared Network         FIRST Interactive Rural SupporT         freelanceFIRST         FIRST Scouting Network         openFIRST         The Grand FIRST Team         FloridaFIRST         Inspiration Foundation Inc.         South Dakota FIRST         FIRST International Partners         FIRSTwiki         Ultimate Robot Challenge         East Coast Drivers Union         Team San Diego         CollegiateFIRST         Dream FIRST         FIRST Brasil         The Blue Alliance             Video Archives     FIRST Historians     FIRST-A-Holic's Anonymous Mailbox     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge         FTC E-Mail Blast Archive     VEX         VEX Robotics Competition     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support         Bulletins and Newsletters     Extra Discussion Old Forum Archives     1999     2000     2001

All times are GMT -5. The time now is 02:15 AM.

The Chief Delphi Forums are sponsored by Innovation First, Inc.

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Team Site - Archive - Top