Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Division versus multiplication matlab mystery - precision

Subject: Division versus multiplication matlab mystery - precision

From: Pat Finder

Date: 23 Mar, 2009 02:36:01

Message: 1 of 3

I have a precision mystery here, when trying to do dynamic range conversion for a 16 bit image:

% Read in the uint16 image:
im = imread( 'uint16.tif');

% FIND THE MIN AND MAX:
mmin = min( im(:) );
mmax = max( im(:) );

% Now, if I do this, it works:
im2 = (im - mmin) / ((mmax - mmin)/256.0);

% But, if I do this, I get an empty matrix:
im2 = (im - mmin) * (256/(mmax - mmin));

Why is there a difference?

Subject: Division versus multiplication matlab mystery - precision

From: Matt Fig

Date: 23 Mar, 2009 02:46:01

Message: 2 of 3

In arithmetic with uint16 values mmax and mmin:

(mmax - mmin)/256.0

is an uint16 with value zero.

Subject: Division versus multiplication matlab mystery - precision

From: Pat Finder

Date: 23 Mar, 2009 03:00:19

Message: 3 of 3

"Matt Fig" <spamanon@yahoo.com> wrote in message <gq6t59$743$1@fred.mathworks.com>...
> In arithmetic with uint16 values mmax and mmin:
>
> (mmax - mmin)/256.0
>
> is an uint16 with value zero.

Right. It does boundary checking and clips to the range. Thanks.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us