from scipy.misc import imread
from matplotlib import pyplot
import cv2
from cv2 import cv
from SRM import SRM
im = imread("lena.png")
im2 = cv2.imread("lena.png")
print type(im), type(im2), im.shape, im2.shape
srm = SRM(im, 256)
segmented = srm.run()
srm2 = SRM(im2, 256)
segmented2 = srm2.run()
pic = segmented/256
pic2 = segmented2/256
pyplot.imshow(pic)
pyplot.imsave("onePic.jpg", pic)
pic = pic.astype('uint8')
cv2.imwrite("onePic2.jpg", pic2)
pyplot.show()
onePic.jpggives the correct segmented image, but onePic2.jpggives a full black image. Converting the data type uint8to using pic = pic.astype('uint8')did not help. I am still giving a black image!
onePic.jpg using pyplot.imsave():

onePic2.jpg using cv2.imwrite():

Please, help!
source
share