tf.image.convert_image_dtype behaves incorrectly on Windows (but fine on MacOS)
@petered Thank you for reporting an issue!
Could you please provide a complete standalone code to replicate this issue?
Thank you! Out of curiosity. Do you know if it changes anything with/without GPU? 

@sushreebarsa this should be enough for you to reproduce ...

```python
import tensorflow as tf
assert int(tf.image.convert_image_dtype(1., tf.uint32))==2**32-1
``` Thanks for looking into it @sushreebarsa  and thanks @DEKHTIARJonathan  for responding.  I never tried with GPU.  Other possibly relevant info - the Mac in question (which provides the correct, continuous version `convert_image_dtype`) is an M1 Mac.   @petered Could you please let us know the exact command you have used to install tensorflow here, it would help us to analyze the issue. Thank you! I believe it was just `pip install tensorflow` though I don't have the command-history available at the moment.  Are you not able to reproduce it? @petered , @DEKHTIARJonathan 

The behaviour is due to the device the operation being executed.Please check the results on Colab(Linux environment) in the attached [gist](https://colab.research.google.com/gist/SuryanarayanaY/5171e789dd75342c0711d9f6405fc4dd/60078.ipynb) with CPU and GPU respectively. The issue is due to casting behaviour on CPU vs GPU with undefined/overflow values.

Please refer to the developer comment for similar issue [here](https://github.com/tensorflow/tensorflow/issues/58749#issuecomment-1467086661).

On MacOS by default the operation seems executing on GPU and on WIndows it is executing on CPU.Hence you are getting different results here.

Thankyou! Thanks @SuryanarayanaY for looking into that.  But it seems MacOS is getting the correct answer on CPU, not just GPU. (I have an M1 2020 Macbook air).  Running

```
import tensorflow as tf
print(tf.__version__)
with tf.device('CPU'):
  print('With CPU:')
  print(tf.image.convert_image_dtype(1., tf.uint32))
```
Prints:
```
2.9.1
With CPU:
tf.Tensor(4294967295, shape=(), dtype=uint32)
```

... Which is the "correct" answer. This is due to undefined behaviour with cast overflow values. Please refer to this [comment](https://github.com/tensorflow/tensorflow/issues/58749#issuecomment-1467086661) for more context.   This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Activity!

On Tue, Apr 25, 2023, 6:54 PM github-actions[bot] ***@***.***>
wrote:

> This issue is stale because it has been open for 7 days with no activity.
> It will be closed if no further activity occurs. Thank you.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/60078#issuecomment-1522648481>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAIYO7ZJ2FOZIQNVWZZLY5DXDB55VANCNFSM6AAAAAAWESRCCY>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
 Hi @petered ,

The issue has been fixed in tf-nightly(2.14.0-dev20230503).Please refer to attached [gist](https://colab.research.google.com/gist/SuryanarayanaY/d168fa4aa643a64d269771ad75bfaa55/60078_r1.ipynb).

But there is one point to note here. Images that are represented using floating point values are expected to have values in the range [0,1).If you are using floats outside this range you need to set `saturate=True` in the API. 

Since floating point inputs to integer types may lead to over/underflow problems. Set saturate to True to avoid such problem in problematic conversions. If enabled, saturation will clip the output into the allowed range before performing a potentially dangerous cast. The same is documented now and you can refer the API Doc [source](https://www.tensorflow.org/api_docs/python/tf/image/convert_image_dtype) for more explanation.

Thank you!


 That's great, thank you for the fix.

On Wed, May 3, 2023, 10:52 PM SuryanarayanaY ***@***.***>
wrote:

> Hi @petered <https://github.com/petered> ,
>
> The issue has been fixed in tf-nightly(2.14.0-dev20230503).Please refer to
> attached gist
> <https://colab.research.google.com/gist/SuryanarayanaY/d168fa4aa643a64d269771ad75bfaa55/60078_r1.ipynb>
> .
>
> But there is one point to note here. Images that are represented using
> floating point values are expected to have values in the range [0,1).If you
> are using floats outside this range you need to set saturate=True in the
> API.
>
> Since floating point inputs to integer types may lead to over/underflow
> problems. Set saturate to True to avoid such problem in problematic
> conversions. If enabled, saturation will clip the output into the allowed
> range before performing a potentially dangerous cast. The same is
> documented now and you can refer the API Doc source
> <https://www.tensorflow.org/api_docs/python/tf/image/convert_image_dtype>
> for more explanation.
>
> Thank you!
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/60078#issuecomment-1534128123>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAIYO73POEXMX5TFVEZ5MJDXEM7YHANCNFSM6AAAAAAWESRCCY>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
 Hi @petered ,

Could you please spare some time to close the issue as it resolved already. Thanks! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60078">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60078">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

2.9.1

### Custom Code

No

### OS Platform and Distribution

Windows

### Mobile device

_No response_

### Python version

3.10

### Current Behaviour?


Compare the result of the line 

```python
tf.image.convert_image_dtype(1., tf.uint32)
```
Between MacOS and Windows.  
* On Mac it returns `tf.Tensor(4294967295, shape=(), dtype=uint32)`
* On windows, `tf.Tensor(0, shape=(), dtype=uint32)`.

It seems that Mac has the correct result - you expect the result to saturate to the max uint32 value of `2**32-1==4294967295` when the float-input is >=1 - but it actually jumps back down to zero.  This caused a very sneaky bug in my code which caused the detection system to fail to detect in some cases.


### Standalone code to reproduce the issue

```python
assert int(tf.image.convert_image_dtype(1., tf.uint32))==2**32-1
```


### Relevant log output

_No response_</details>