Ask Your Question

Revision history [back]

Difference in zeros values after saving image and then reading again

Here's my code snippet:

        non_zeros = np.transpose(np.nonzero(self.host))
        print 'Before imwrite and imread'
        print non_zeros
        cv2.imwrite(final_img_name ,self.host)
        out = cv2.imread(final_img_name, 0)
        non_zeros = np.transpose(np.nonzero(out))
        print 'After imwrite and imread'
        print non_zeros

The output is as follow:

Before imwrite and imread
[[ 32 328]
 [141 175]]
After imwrite and imread
[[ 32 328]
 [ 32 329]
 [ 33 328]
 [ 35 331]
 [ 35 332]
 [ 36 331]
 [ 39 332]
 [136 171]
 [136 172]
 [137 168]
 [137 169]
 [138 172]
 [138 173]
 [138 174]
 [138 175]
 [139 170]
 [139 171]
 [140 170]
 [140 171]
 [140 175]
 [141 174]
 [141 175]
 [142 168]
 [142 169]
 [142 170]
 [142 174]
 [142 175]
 [143 171]
 [143 172]]

Why non-zeros elements get added ? The values of non-zeros elements change as well (Like 10 become 1,2,3,...).

I'm working in certain application where there's not scope for any tolerance.

What's wrong ? What should I do ?

click to hide/show revision 2
retagged

updated 2014-03-14 05:23:47 -0500

berak gravatar image

Difference in zeros values after saving image and then reading again

Here's my code snippet:

        non_zeros = np.transpose(np.nonzero(self.host))
        print 'Before imwrite and imread'
        print non_zeros
        cv2.imwrite(final_img_name ,self.host)
        out = cv2.imread(final_img_name, 0)
        non_zeros = np.transpose(np.nonzero(out))
        print 'After imwrite and imread'
        print non_zeros

The output is as follow:

Before imwrite and imread
[[ 32 328]
 [141 175]]
After imwrite and imread
[[ 32 328]
 [ 32 329]
 [ 33 328]
 [ 35 331]
 [ 35 332]
 [ 36 331]
 [ 39 332]
 [136 171]
 [136 172]
 [137 168]
 [137 169]
 [138 172]
 [138 173]
 [138 174]
 [138 175]
 [139 170]
 [139 171]
 [140 170]
 [140 171]
 [140 175]
 [141 174]
 [141 175]
 [142 168]
 [142 169]
 [142 170]
 [142 174]
 [142 175]
 [143 171]
 [143 172]]

Why non-zeros elements get added ? The values of non-zeros elements change as well (Like 10 become 1,2,3,...).

I'm working in certain application where there's not scope for any tolerance.

What's wrong ? What should I do ?