Skip to content Skip to sidebar Skip to footer

What Is The Equivalent Of Imagesc In Opencv

What would be the equivalent of imagesc in OpenCV?

Solution 1:

To get the nice colors in imagesc you have to play around with OpenCV a little bit. In OpenCV 2.46 there ss a colormap option.

This is code I use in c++. Im sure its very similar in Python.

mydata.convertTo(display, CV_8UC1, 255.0 / 10000.0, 0); 
applyColorMap(display, display, cv::COLORMAP_JET);
imshow("imagesc",display);

The image data or matrix data is stored in mydata. I know that it has a maximum value of 10000 so I scale it down to 1 and then multiply by the range of CV_8UC1 which is 255. If you dont know what the range is the best option is to first convert your matrix in the same way as Matlab does it.

EDIT

Here is a version which automatically normalizes your data.

floatAmin= *min_element(mydata.begin<float>(), mydata.end<float>());
floatAmax= *max_element(mydata.begin<float>(), mydata.end<float>());
MatA_scaled= (mydata - Amin)/(Amax - Amin);
A_scaled.convertTo(display, CV_8UC1, 255.0, 0); 
applyColorMap(display, display, cv::COLORMAP_JET);
imshow("imagesc",display);

Solution 2:

It's close to imshow in matlab.

It depends on modules you use in python:

import cv2
import cv2.cv as cv

I_cv2 = cv2.imread("image.jpg")
I_cv = cv.LoadImage("image.jpg")

#I_cv2 is numpy.ndarray norm can be done easily
I_cv2_norm = (I_cv2-I_cv2.min())/(I_cv2.max()-I_cv2.min())
cv2.imshow("cv2Im scaled", I_cv2_norm)

#Here you have to normalize your cv iplimage as explain by twerdster to norm
cv.ShowImage("cvIm unscaled",I_cv)

The best way I think to be close to imagesc, is to use cv2.imread which load image as numpy.ndarray and next use imshow function from matplotlib.pyplot module:

import cv2
from matplolib.pyplot import imshow, show
I = cv2.imread("path")
#signature:
imshow(I, cmap=None, norm=None, aspect=None, interpolation=None,
             alpha=None, vmin=None, vmax=None, origin=None, extent=None,
             **kwargs)

Here you can choose whatever you want if normalized or your clims (scale)...

Post a Comment for "What Is The Equivalent Of Imagesc In Opencv"