Display image with format .mat in OpenCV Python - python

I am trying to replicate a code taht I did in MATLAB to Python, using OpenCV.
I have an image with .mat format that I managed to load, however I cannot displayed it using cv2.imshow(), since it does not supports it.
So does anyone know how I can visualize my image??
#Load image
import scipy.io as sio
matimage='img1.mat'
img = sio.loadmat(matimage)
cv2.imshow('Image', img)
Thanks in advance!

Related

OpenCV tiling TIFF image on loading with imread

I have a 32-bit 3-band TIF image that I am trying to load using OpenCV with Python. I'm specifically avoiding GDAL as it is not user-friendly to install on Windows, and this script is targeted at Windows machines.
When I try to load the image with imread (
img = cv2.imread(file, flags=(cv2.IMREAD_UNCHANGED | cv2.IMREAD_ANYDEPTH))
), and either write it out or imshow it, the 3 bands appear to be tiled, like so:
For comparison, rendering in Windows looks like this:
So there should be no issue from an OS support perspective.
GIMP Properties for image:
Is there a way to override this behaviour? Is there a known cause to this?
I found a solution. Using the tifffile library in conjunction with scikit-image, I was able to load my TIFFs in a format understandable by OpenCV.
Thus, my load statement became:
img = skimage.io.imread(file,plugin='tifffile')
And the image:

Save Numpy array graphs and images as images

I cannot find a way to save my graphs and images. I have tried from
from PIL import Image
im = Image.fromarray()
im.save("your_file.jpeg")
but doesn't work!
Please format your code correctly, it is important for readability and python is intend-sensitive. Also, there is already a post for this problem:
How can I save an image with PIL?

Image from sqlite database used for face recognization using python

I have store the image in sqlite3 database using BLOB datatype and I need to extract that image for facial recognition . I have been using face recognition package to do so. The problem is i am not able to use extracted image for encoding and other operation. So, I think I have to change the datatype of the image for further processing but I am not able to find so.
The error for the code is:
RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
The problem is you need to properly read the face images.
There are multiple libraries for that operation. For instance: opencv, Pillow, skimage, etc.
Here is an example of how you can read the face image:
from PIL import Image
for face in data:
face_array = Image.open(face)

how to use opencv to convert an image into a matrix in Python

I have read the documentation of opencv regarding image processing but I am still pretty new to opencv. I am trying to convert some images into matrix so that I can do some classification after that. Can anyone help tell me how I should start this? Thanks so much!
If you simply read an image with opencv in python, you will get it in a matrix.
Eg.:
import cv2
img = cv2.imread('a.jpg',0)
type(img)
Out[3]: numpy.ndarray
img.shape
Out[4]: (200, 200)

opencv python- noise in saved image via io.imsave

i am trying to save an image in opencv python. the image that the program is showing via cv2.imshow() is perfectly fine. but when i am saving it using cv2.imwrite() it is saving black image .then i have tried io.imsave for saving but it is also saving my image with some gray small blobs on that.
i am saving it with .png extension.i have also tried to save with other extensions but nothing works fine for me.
cv2.imshow('result',res)
io.imsave('gabor.png',res)
can anyone point out what can be the problem?

Categories

Resources