Skip to content

Instantly share code, notes, and snippets.

@johnnyferreiradev
Created March 16, 2019 14:43
Show Gist options
  • Save johnnyferreiradev/1974e5d325405b27aedec9cd7c150d78 to your computer and use it in GitHub Desktop.
Save johnnyferreiradev/1974e5d325405b27aedec9cd7c150d78 to your computer and use it in GitHub Desktop.
Operadores de Prewitt para processamento digital de imagens (Filtro 3x3)
Mat operadoresPrewitt(Mat img){
Mat imgResultante = img.clone();
int gx,gy;
for(int i=0; i< img.rows; i++){
for(int j=0; j < img.cols; j++){
gx = (img.at<uchar>(i-1,j+1) + img.at<uchar>(i,j+1) + img.at<uchar>(i+1,j+1)) -
(img.at<uchar>(i-1, j-1) + img.at<uchar>(i, j-1) + img.at<uchar>(i+1, j-1));
gy = (img.at<uchar>(i+1,j-1) + img.at<uchar>(i+1,j) + img.at<uchar>(i+1,j+1)) -
(img.at<uchar>(i-1, j-1) + img.at<uchar>(i-1, j) + img.at<uchar>(i-1, j+1));
imgResultante.at<uchar>(i,j) = sqrt(pow(gx, 2) + pow(gy, 2));
}
}
return imgResultante;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment