Needs["CV`"];
CVOpen[];
            
img=CVLoadImage["airplane.jpg",CVLoadImageGrayScale];
array = CVGetImageArray[img,1,1];
                
Image[array]
hist=CVCreateHist[{256},CVHistArray,{{0,255}},1];
CVCalcHist[{img},hist,0,0];
h=CVGetHistArray[hist];
ListPlot[h,PlotRange->{{0,255},{0,5000}}]
minmax=CVGetMinMaxHistValue[hist]
CVNormaliszeHist[hist,1.0];
s=CVGetSize[img];
img2=CVCreateImage[s,IplDepth8U,1];
                
CVConvertScale[img,img2,255.0/(170-50),-50.0*255.0/(170-50)];
CVCalcHist[{img2},hist,0,0];
h=CVGetHistArray[hist];
                
ListPlot[h,PlotRange->{{0,255},{0,5000}}]
Image[CVGetImageArray[img2,1,1]]
img3=CVCreateImage[s,IplDepth8U,1];
CVThreshold[img2,img3,50.0,255.0,CVThreshBinary];
                
Image[CVGetImageArray[img3,1,1]]
img4=CVLoadImage["baboon.jpg",CVLoadImageUnchanged];
array=CVGetImageArray[img4,1,-1];
                
Image[array]
s=CVGetSize[img4];
blue=CVCreateImage[s,IplDepth8U,1];
green=CVCreateImage[s,IplDepth8U,1];
red=CVCreateImage[s,IplDepth8U,1];
                
CVSplit[img4,blue,green,red,0]
Image[CVGetImageArray[red,1,1]]
CVCvtColor[img4,img4,CVBGR2HSV]
hue=CVCreateImage[s,IplDepth8U,1];
sat=CVCreateImage[s,IplDepth8U,1];
val=CVCreateImage[s,IplDepth8U,1];
CVSplit[img4,hue,sat,val,0]
                
histHS=CVCreateHist[{20,20},CVHistArray,{{0,180},{0,255}},1];
CVCalcHist[{hue,sat},histHS,0,0]
minmax=CVGetMinMaxHistValue[histHS]
histImg=CVGetHueSatHistImage[histHS,10];
Image[CVGetImageArray[histImg,1,-1]]
CVClose[]
