0

I'm reading about local binary pattern and I've the following code to extract local binary pattern.

from skimage import feature
import cv2 as  cv 
img = cv.imread("image.jpg",0)
lbp = feature.local_binary_pattern(img,8,1,"default")
cv.imshow("LBP",lbp)

the output image look like this

enter image description here

the original image is
enter image description here
But when I save image and load it back using the following code

from skimage import feature
import cv2 as  cv 
img = cv.imread("image.jpg",0)
lbp = feature.local_binary_pattern(img,8,1,"default")
cv.imwrite("new_lbp.jpg",lbp)
newim = cv.imread("new_lbp.jpg",0)
cv.imshow("new image",newim)

the image looks like this.
enter image description here

why does this two images looks different? can any body help me understand it?

Mitiku
  • 5,337
  • 3
  • 18
  • 35
  • Weren't you supposed to use `newim` while `cv.imshow("new image",img)` – ZdaR Oct 14 '17 at 09:13
  • @ZdaR yes you are right i've just edited the code. – Mitiku Oct 14 '17 at 09:15
  • Then the outputs must have changed as well @Mitiku ? – ZdaR Oct 14 '17 at 09:15
  • @ZdaR The made the mistake when posting to stackoverflow, not inside local code. – Mitiku Oct 14 '17 at 09:17
  • imwrite and imread are for **images**. Not all matrices represent images. Your "lbp" contains values which do not represent pixels. You can save/load as you would do for any other numpy array and you'll be fine – Miki Oct 14 '17 at 11:42

1 Answers1

-2

Opencv have some problems while saving jpg images so you can use other formats like bmp

onur aslan
  • 283
  • 3
  • 8
  • It should be **png** not **bng**. – Jeru Luke Oct 14 '17 at 11:37
  • Yes but it should be bmp – onur aslan Oct 14 '17 at 11:55
  • it could be any lossless image format, but this is not the case since the data don't represent pixel values. – Miki Oct 14 '17 at 11:56
  • Note OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins (you need to specify to use them if you build yourself the library, nevertheless in the packages we ship present by default) you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 - codenamed in the CMake as Jasper), TIFF files (tiff, tif) and portable network graphics (png).For more read this [link](https://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html) – onur aslan Oct 14 '17 at 12:00