Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Steve on Image Processing

March 9th, 2007

What happened to isgray, isind, isbw, and isrgb?

In a blog comment recently, Rob asked about what happened to isrgb. When you run this function, it issues a warning about being obsolete. Rob asked "What were the toolbox developers thinking?"

The function isrgb is closely related to isgray, isind, and isbw, which are also obsolete. I thought I'd try to explain the original purpose of these functions, as well as why they are now obsolete.

When the Image Processing Toolbox was first being created, in 1992-93, the only MATLAB data type was a two-dimensional, double-precision matrix. There were no integer arrays, no logical arrays, etc. Many toolbox functions were intended to operate on more than one type of image: grayscale, indexed, binary, RGB. Some functions used different algorithms or different defaults, depending upon the input image type. Such a function might have used isgray, etc., like this:

function B = imfoobar(A)

if isbw(A)
  B = do_the_binary_thing(A);  

elseif isind(A)
  B = do_the_indexed_thing(A);

elseif isgray(A)
  B = do_the_grayscale_thing(A);

else
  error('Try, try again'); 
end

There were three problems with this coding pattern:

  • Performance
  • Ambiguity
  • Undesirable limits on input data

The performance problem was that the is* functions read and performed tests on every matrix value. isbw(A) tested to see if every element of A was either 0 or 1. isind(A) tested to see if every value was an integer no smaller than 1. (There were no 0-based uint8 indexed images back then.) isgray(A) tested to see if every value was in the range [0.0, 1.0]. As we worked to speed up toolbox functions in the mid-90s, it became apparent that these function calls limited how fast we could get.

The ambiguity problem was simply this: All of these functions would return true for an all-ones matrix. Also, isgray(A) and isbw(A) would both return true for a matrix containing only zeros and ones. There was simply no way to reliably distinguish the image types from one another based only on the matrix values. By this time in the history of MATLAB development, we were beginning to learn hard lessons about ambiguous syntax designs. Even seemingly benign ambiguities, such as logical indexing, or all those functions that worked down the columns (except when they didn't), were coming back to haunt us.

There's another type of ambiguity associated with these functions. Consider a 100-by-200-by-3 array, for instance. Is it an RGB image? Or a YCbCr image? Maybe it's 3 slices of an MRI, or three frames from a video sequence. The function isrgb can't really tell.

Finally, there was this important principle of Image Processing Toolbox function design: Except for functions that MUST associate a value with a particular color, toolbox functions should make no particular assumptions about the valid range of input values. Display functions and colorspace conversions obviously have to assign colors to matrix values. But most toolbox functions are purely mathematical operations that don't necessarily have anything to do with color, and which can operate on any values. Convolution (imfilter) is an example. Our engineering and scientific customers aren't typically doing picture processing; they are looking at and operating on data using image processing operators. And their data could be in any range, and often had meaningful physical units. Because of this principle, most toolbox functions should not impose any kind of data range restriction, and therefore it generally isn't that useful to be calling isgray(A) to see if the input was in the range [0.0, 1.0].

So eventually we deprecated these functions, stopped using them within the toolbox, and modified toolbox syntaxes to remove ambiguities associated with testing for image type.

In most cases, the person writing the code knows the context of how the matrix or multidimensional array was created or obtained, and so knows whether the code should treat the input as RGB or YCbCr or whatever. The most common case where it makes sense to detect the image type is when you are processing image files. For example, you have a directory full of TIFF files, and some are indexed, some are RGB, etc. In this case, I recommend that you determine the image type directly from the output of imfinfo.

The bottom line is that these functions promise something they can't really deliver. If the functions weren't deprecated, people would be forever confused about how exactly they are supposed to behave, as well as when they should be used.

6 Responses to “What happened to isgray, isind, isbw, and isrgb?”

  1. Rob replied on :

    Steve,

    Thanks for the explanation of how the is* functions evolved, and the lessons you learned from them. That is exactly what I had in mind when requesting to know “what they were thinking” when decisions like these are often made. Makes sense, and I’ll be using imfinfo now instead of testing whole matrices. I was aware of the false positives you could get from them, but honestly had not considered the speed impact.

    Regards,
    Rob

  2. samar damlakhi replied on :

    Dear Mr.Eddins
    I am a self_learning about matlab (image toolbox),
    i am working on roots of the olive to constract the sub_branchs and main_branchs (length_width)after doing a perfect thresholding to work on binary images
    i will really aprciate if you let me in contact while i’m preparing my algorithms for the roots
    Best Regards

  3. james replied on :

    Hi steve I have a request
    when I have several 3D cordinate
    How I can recive equation of that coordinate
    Thanks

  4. Steve replied on :

    James - I’m sorry, but I don’t understand your question. It it about image processing, and can you be much more specific?

  5. hanaa saleh replied on :

    i mant to perform the ambiguity function on thr evoked potential of EEG signals and use fisher contrast for classification how i find ambiguity function and fisher contrast and perform them on matlab

  6. Steve replied on :

    Hanaa - I don’t have information on those terms and operations. May I suggest that you use libraries, journals, books, and Internet searches?

Leave a Reply


Steve Eddins manages the Image & Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.

  • ismail: i love chess keep posting :) can we make a web cam identify a chess set ? so we have a roboarm plays for real...
  • Navan: While black is going to win with a smothered mate, it is hard to see what moves would have led to this...
  • Doug: Forced ’smothermate&# 8217; is about to happen, with the added insult of threatening the queen on the...
  • Viton: Let’s give it a try: - RxQ : White Rook takes black Queen (White King was checked, can’t take...
  • Omar: Hi Steve, when using tformfwd to find corresponding points in the new space, the resulting co-ordinates from...
  • Steve: Cris—You’ ;re right, I should have caught the plot scaling issue. I wasn’t actually trying...
  • Cris Luengo: Not to spoil your upcoming bog entry too much, but if you scale the first graph (times vs Q) by setting...
  • Steve: Jim—Thanks for adding your comment showing how the syntax works for matrices.
  • Jim: for i = A …statements 230; end; Description: The …statements 230; are executed (as MATLAB...
  • Steve: Omar—Nice work.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics