Question:

In this command in "Matlab", what is the purpose of dividing by "256"?>> imshow(filter2(g,c)/256)

by  |  earlier

0 LIKES UnLike

In this command in "Matlab", what is the purpose of dividing by "256"?>> imshow(filter2(g,c)/256)

 Tags:

   Report

2 ANSWERS


  1. Actually, imshow can handle elements from 0 to 255 if the variable's type is 'uint8'. If the type is double, then it won't scale the colors properly unless they're in the range [0,1]. So rather than dividing by 256, one could also cast the variable to a uint8:

    imshow(uint8(filter2(g,c)));

    Alternatively, you can use imagesc instead of imshow, which automatically scales its input to maximize the viewable dynamic range. I find the following steps useful for general floating point images:

    imagesc(im);

    colormap hot;

    colorbar;

    axis equal;

    Hope that helps.


  2. 256 is the common number of shades in an 8-bit color channel.

    It's likely the output of filter2() is in 8-bit color.

    imshow() takes color values in a range from 0 to 1.

    Dividing the output of filter2() by 256 converts the color values to something imshow() can work with.

    Without knowing what g and c represent though, it's pretty much just a random guess.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.