Reputation: 165
i wrote this algorithm for a future erosion implementation. I'm testing the algorithm but i've got this problem:
when i try to color all pixel with white colour i get a image with column black and white, otherwise if i set each pixel black it worked. how i can solve?
here's my code
Mat Morph_op_manager::erode_img(Mat image) {
//stucture element attribute
int strel_rows = 5;
int strel_cols = 5;
// center structure element attribute
int cr = 3;
int cc = 3;
//number of columns/rows after strel center
int nrac = strel_rows - cr ;
int ncac = strel_cols - cr ;
int min_val = 255;
for (int i = cr-1 ; i <image.rows-nrac ; i++) {
for (int j = cc-1; j < image.cols-ncac ; j++) {
for (int ii = 0; ii <strel_rows ; ii++) {
for (int jj = 0; jj <strel_cols ; jj++) {
image.at<int>(i-(nrac-ii),j-(ncac-jj)) = 255;
}
}
}
}
i'm working with opencv in c++, file is a black and white image .tiff. here's my output
Upvotes: 0
Views: 70
Reputation: 4542
I don't see how you declared your image
object but I bet it is of type CV_8U
.
When you access the pixels you should write image.at<uchar>((i-(nrac-ii),j-(ncac-jj))
instead of image.at<int>((i-(nrac-ii),j-(ncac-jj))
. That's because you declared that the data in the matrix would be uchar
(CV_8U) and not int
(CV_32S).
Upvotes: 1