Oh, right, sorry, now I see what you're doing.

Arrays are homogeneous, meaning every value has the same type. If you write:

imgs[i, 0] = imgs[i, 0].astype(np.uint8)

you are not changing the type of imgs, so you explicitly cast to uint8 and then the assignment (=) implicitly casts it back to float64. Oops! =)

Please follow the advice of Egor and find the img_as_ubyte and img_as_float methods, and use those to convert images of different types.

Juan.


On 28 Dec 2016, 2:48 AM +1100, wine lover , wrote:
Hi Juan,

Thanks for pointing the typo. I corrected it, and looks like imgs[i,0]=imgs[i,0].astype(np.unit8) does not solve the problem.

Here is the screenshot of result

imgs[i,0]  (584, 565)
imgs[i,0]  float64
imgs[i,0]  255.0
imgs[i,0]  0.0
afte applying astype
imgs[i,0]  (584, 565)
imgs[i,0]  float64
imgs[i,0]  255.0
imgs[i,0]  0.0

Thanks,
Yuanyuan



On Tue, Dec 27, 2016 at 12:10 AM, Juan Nunez-Iglesias <jni.soma@gmail.com> wrote:
Typo: unit8 -> uint8


On 27 Dec 2016, 9:27 AM +1100, wine lover <winecoding@gmail.com>, wrote:
Dear All,

I was trying to use the above code segment for performing Contrast Limited Adaptive Histogram Equalization (CLAHE).
def clahe_equalized(imgs):
    imgs_equalized = np.empty(imgs.shape)
    for i in range(imgs.shape[0]):
         
         print('imgs[i,0] ',imgs[i,0].dtype)
         print('imgs[i,0] ',imgs[i,0].max())
         print('imgs[i,0] ',imgs[i,0].min())
         imgs_equalized[i,0] = exposure.equalize_adapthist(imgs[i,0],clip_limit=0.03)
    return imgs_equalized

The dtype is float64, maximum value is 255.0 and minimum value is 0.0

Running the program generates the following error message ( I only keep the related ones)

imgs_equalized[i,0] = exposure.equalize_adapthist(imgs[i,0],clip_limit=0.03)
   raise ValueError("Images of type float must be between -1 and 1.")
ValueError: Images of type float must be between -1 and 1.  

In accordance with the above error message and image characteristics, what are the best way to handle this scenario. 

I have been thinking of two approaches

  1. add imgs[i,0] = imgs[i,0]/255.   which scale it to 0 and 1
  2.  convert imgs[i,0] from float64 to unit8 
but imgs[i,0] = imgs[i,0].astype(np.unit8) gives the error message such as
 imgs[i,0]=imgs[i,0].astype(np.unit8)                                                              
AttributeError: 'module' object has no attribute 'unit8'       

Would you like to give any advice on this problem? Thank you very much!  


_______________________________________________
scikit-image mailing list
scikit-image@python.org
https://mail.python.org/mailman/listinfo/scikit-image



On 27 Dec 2016, 9:27 AM +1100, wine lover <winecoding@gmail.com>, wrote:
Dear All,

I was trying to use the above code segment for performing Contrast Limited Adaptive Histogram Equalization (CLAHE).
def clahe_equalized(imgs):
    imgs_equalized = np.empty(imgs.shape)
    for i in range(imgs.shape[0]):
         
         print('imgs[i,0] ',imgs[i,0].dtype)
         print('imgs[i,0] ',imgs[i,0].max())
         print('imgs[i,0] ',imgs[i,0].min())
         imgs_equalized[i,0] = exposure.equalize_adapthist(imgs[i,0],clip_limit=0.03)
    return imgs_equalized

The dtype is float64, maximum value is 255.0 and minimum value is 0.0

Running the program generates the following error message ( I only keep the related ones)

imgs_equalized[i,0] = exposure.equalize_adapthist(imgs[i,0],clip_limit=0.03)
   raise ValueError("Images of type float must be between -1 and 1.")
ValueError: Images of type float must be between -1 and 1.  

In accordance with the above error message and image characteristics, what are the best way to handle this scenario. 

I have been thinking of two approaches

  1. add imgs[i,0] = imgs[i,0]/255.   which scale it to 0 and 1
  2.  convert imgs[i,0] from float64 to unit8 
but imgs[i,0] = imgs[i,0].astype(np.unit8) gives the error message such as
 imgs[i,0]=imgs[i,0].astype(np.unit8)                                                              
AttributeError: 'module' object has no attribute 'unit8'       

Would you like to give any advice on this problem? Thank you very much!  


_______________________________________________
scikit-image mailing list
scikit-image@python.org
https://mail.python.org/mailman/listinfo/scikit-image