# FITS image processing with OpenCV Python

**URL:** <https://community.openastronomy.org/t/fits-image-processing-with-opencv-python/594>\
**Category:** OpenAstronomy\
**Tags:** astropy, fits, question\
**Created:** [March 3, 2023, 11:54am UTC](https://community.openastronomy.org/t/fits-image-processing-with-opencv-python/594 "2023-03-03T11:54:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TAram](https://avatars.discourse-cdn.com/v4/letter/t/58956e/32.png) [@TAram](https://community.openastronomy.org/u/TAram)\
**Post date:** [March 3, 2023, 11:54am UTC](https://community.openastronomy.org/t/fits-image-processing-with-opencv-python/594/1 "2023-03-03T11:54:36Z")

</div>

I want to detect stars on fits astronomical image. For detection I need to use OpenCV library. But have problems with data formats and converting. How can I open FITS file (data format float32) for working with OpenCV, which works in format uint8? How to convert float32 to uint8?

---

<div class="post-metadata">

**Author:** ![GregAlt](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@GregAlt](https://community.openastronomy.org/u/GregAlt)\
**Post date:** [November 18, 2023, 3:51pm UTC](https://community.openastronomy.org/t/fits-image-processing-with-opencv-python/594/2 "2023-11-18T15:51:41Z")

</div>

Sorry a bit late, but i think you’d want something like this for the image array itself:

def float01to8bit(im):  
return (im\*255).astype(np.uint8)

Also might make sense to normalize to 0-1 first with something like:

im = cv.normalize(im, None, 0,1, cv.NORM\_MINMAX)
