bin2gray function's input is decimal.
6 views (last 30 days)
Show older comments
if dec2bin converts decimal to binary. and hex2dec converts hexadecimal to decimal. then how come bin2gray converts DECIMAL to gray?
0 Comments
Accepted Answer
Walter Roberson
on 30 May 2015
Edited: Walter Roberson
on 30 May 2015
>> why
The terrified engineer wanted it that way.
>> why
Barney suggested it.
>> why
To please a hamster.
It is for the same reason that you can get set to set a set of plates on a table. Some words have multiple meanings, and the meaning depends on context.
dec2bin() and hex2dec() deal with matters of presentation of values to and from characters. bin2gray() deals with error coding theory.
When practical, MATLAB is written to use terms that would be familiar and easily recognizable to the people who work in the field that the function applies to. The point is to be useful to people, not to force them to learn a terminology in which each phrase ("dec") has only a single meaning.
The fault, if there is one, is in the naming of "dec2bin". Perhaps it should have been named something like bindouble2binint322binstr, and then people would learn that dec2bin(42) was too sloppy as a name because it doesn't specifically point out that the 42 was internally represented as the double-precision-interpreted binary 100000001000101000000000000000000000000000000000000000000000000 and needs to be converted to the integer-interpreted 32 bit binary 0000000000000000000000000101010 which in turn needs to be converted (as the main functionality of the routine) to the string '101010'. Those things are important to think about every time one wants to convert a number, right?!
More Answers (1)
Image Analyst
on 29 May 2015
You'll have to ask whomever wrote it. It's not part of MATLAB.
A built-in MATLAB function to convert floating point numbers in any range to grayscale is called mat2gray() . It scales the min to 0 and the max to 1. If you want a uint8 image, you can do
grayImage = uint8(255 * mat2gray(floatingPointMatrix));
3 Comments
Image Analyst
on 30 May 2015
Thanks Walter. I've added the Communications System Toolbox to the Products list for Elad. If he had put that there, I would have figured out where that function came from.
Elad, it's in a special toolbox that you have so that's why it shows up in your MATLAB help but not mine . I don't think it's a common toolbox - only 188 of 159,300 questions here in Answers deal with it. The most discussed toolboxes here are Imaging and Signal - #1 and 2 toolboxes respectively.
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!