Opencv histogramidan foydalanib, tasvir bloklari vositalarini qanday aniqlash mumkin

Gistogramma yordamida tasvirimning o'rtacha blokini aniqlashni xohlayman. Tasavvurim 64 o'lchamda 64 o'lchamga ega, uni 4-dan 4-blokga bo'linib, keyin har bir blokning o'rtacha qiymatini belgilash kerak (boshqa so'z bilan aytadigan bo'lsam, hozirda 4 ta blok bor).

Opencv dan foydalanib, histogram qutilari yordamida bloklar ma'nosini aniqlash uchun IplImagedan qanday foydalanishim mumkin?

Quyidagi kod butun rasmni aniqlash uchun ochilgan histogram hisoblanadi:

int i, hist_size = 256;
float max_value,min_value;
float min_idx,max_idx;
float bin_w;
float mean =0, low_mean =0, high_mean =0, variance =0;

float range_0[]={0,256};
float *ranges[]={range_0};

IplImage* im = cvLoadImage("killerbee.jpg");
//Create a single planed image of the same size as the original
IplImage* grayImage = cvCreateImage(cvSize(im->width,im->height),IPL_DEPTH_8U, 1);
//convert the original image to gray
cvCvtColor(im, grayImage, CV_BGR2GRAY);

/* Remark this, since wanna evaluate whole area.
    //create a rectangular area to evaluate
    CvRect rect = cvRect(0, 0, 500, 600 );
    //apply the rectangle to the image and establish a region of interest
    cvSetImageROI(grayImage, rect);
End remark*/

//create an image to hold the histogram
IplImage* histImage = cvCreateImage(cvSize(320,200), 8, 1);
//create a histogram to store the information from the image
CvHistogram* hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1);
//calculate the histogram and apply to hist
cvCalcHist( &grayImage, hist, 0, NULL );

//grab the min and max values and their indeces
cvGetMinMaxHistValue( hist, &min_value, &max_value, 0, 0);
//scale the bin values so that they will fit in the image representation
cvScale( hist->bins, hist->bins, ((double)histImage->height)/max_value, 0 );

//set all histogram values to 255
cvSet( histImage, cvScalarAll(255), 0 );
//create a factor for scaling along the width
bin_w = cvRound((double)histImage->width/hist_size);

for( i = 0; i < hist_size; i++ ) {
    //draw the histogram data onto the histogram image
    cvRectangle( histImage, cvPoint(i*bin_w, histImage->height),cvPoint((i+1)*bin_w,histImage->height - cvRound(cvGetReal1D(hist->bins,i))),cvScalarAll(0), -1, 8, 0 );
    //get the value at the current histogram bucket
    float* bins = cvGetHistValue_1D(hist,i);
    //increment the mean value
    mean += bins[0];
}
//finish mean calculation
mean /= hist_size;

//display mean value onto output window
cout<<"MEAN VALUE of THIS IMAGE : "<<"\n";

//go back through now that mean has been calculated in order to calculate variance
for( i = 0; i < hist_size; i++ ) {
    float* bins = cvGetHistValue_1D(hist,i);
    variance += pow((bins[0] - mean),2);
}
//finish variance calculation
variance /= hist_size;
cvNamedWindow("Original", 0);
cvShowImage("Original", im );

cvNamedWindow("Gray", 0);
cvShowImage("Gray", grayImage );

cvNamedWindow("Histogram", 0);
cvShowImage("Histogram", histImage );

//hold the images until a key is pressed
cvWaitKey(0);

//clean up images
cvReleaseImage(&histImage);
cvReleaseImage(&grayImage);
cvReleaseImage(&im);

//remove windows
cvDestroyWindow("Original");
cvDestroyWindow("Gray");
cvDestroyWindow("Histogram");

Oldindan rahmat.

0

1 javoblar

Buni histogramlar orqali qilishingiz mumkin, lekin buni amalga oshirish uchun juda samarali usul deyarli xohlagan ishni bajaradigan ajralmas tasvirdir.

Bu yerdan http://en.wikipedia.org/wiki/Summed_area_table dan keyin uni hisoblash uchun foydalaning. har bir blokdagi barcha piksellarning yig'indisi. Keyin har bir blokda piksel soniga bo'linadi (4x4 = 16). Yaxshi emasmi?

OpenCV integrallashtirilgan tasvirni hisoblash funktsiyasiga ega, bunda cv: integral ()

Buni amalga oshirishning eng oson usuli - kamtarona o'lchamlarni ().

Chaqiruv o'lchamlarini o'zgartirish (image64_64, image_16_16, Size (16, 16), INTER_AREA) va natija piksel qiymatlari siz izlayotgan qiymatlarga ega bo'lgan kichikroq rasm bo'ladi. Bu ajoyibmi?

Faqat INTER_AREA bayrog'ini unutmang. Foydalanadigan to'g'ri algoritmni aniqlaydi.

0
qo'shib qo'ydi
Sizning javobingiz va tushunishingiz uchun tashakkur, chunki men boshqa maqsadlar uchun histogramga muhtojman, shuning uchun men hali ham histogramdan foydalanishni afzal ko'raman. Blokni aniqlash uchun histogramdan foydalanishni davom ettirishga oid har qanday fikrni anglatadimi?
qo'shib qo'ydi muallif Mr.K, manba