Ice waterway learning notes

Learning contents and References:

[1] Wang Yu, Ma Yuxian, Chen Yuan, Chen Weibin. Morphological characteristics analysis of Arctic interglacial waterways based on satellite images [J]. Journal of marine technology, 2019,38 (02): 8-13
[2] Cunningham G F, Kwok R, Banfield J. Ice lead orientation characteristics in the winter Beaufort Sea [C]// International Geoscience & Remote Sensing Symposium, IEEE, 1994
[3]Tschudi M A, Curry J A, Maslanik J A. Characterization of springtime leads in the Beaufort/Chukchi Seas from airborne and satellite
observations during FIRE/SHEBA[J]. Journal of Geophysical Research Oceans, 2002, 107(C10):SHE 9-1-SHE 9-14
[4]Banfield J. Skeletal modeling of ice leads[J]. IEEE Transactions on Geoscience & Remote Sensing, 1992, 30(5):918-923

1, Extract the skeleton of the interglacial channel

1.1 premise:

The remote sensing image of the study area is segmented into a binary image by threshold, and the skeleton of the ice channel is extracted by Hilditch algorithm.

1.2 method:

Hilditch algorithm

1.2.1 principle:

The main steps of the algorithm are traversing image pixels. In one traversal, for each pixel, if 6 conditions are met at the same time, it will be marked as to be removed. After one traversal, if there are pixels to be removed, the values of all pixels to be removed in this traversal will be changed. Then restart the traversal until there are no pixels to be removed, and the traversal ends.

1.2.2 six judgment conditions:

① The current pixel P value is 1, that is, it is not the background.
② At least one of the upper, lower, left and right neighbors of P has a value of 0.
③ At least 2 of the eight neighbors of P are 1.
④ At least one of the eight neighbors of P has a value of 1 and is not marked for removal.
⑤ Calculate the number of connections of P (choose one of the two schemes):

  • 4. Calculation formula of connected connection number:

  • 8. Calculation formula of connected connection number:

    ⑥ If x3 and x5 are marked for removal, recalculate the number of connections with x3=0 and x5=0, respectively, and be equal to 1.
    Hilditch reference original link: link.

1.3 opencv code

#include <iostream>
#include <opencv2\opencv.hpp>
 
using namespace std;
using namespace cv;
int Judge_Condition1(Mat &src, int i, int j);
int Judge_Condition2(Mat &src, int i, int j);
int Judge_Condition3(Mat &src, int i, int j);
int Judge_Condition4(Mat &mask, Mat &src, int i, int j);
int Judge_Condition5(Mat &mask, Mat &src, int i, int j);
struct Direct
{
	int x;
	int y;
};  //Directional structure
	//Define n0...n7 eight directions
Direct N[8] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };
int main(void)
{
	//Read picture
	Mat src = imread("K:/line.jpg");
	Mat image;
	//Convert to grayscale image
	cvtColor(src, image, CV_BGR2GRAY);
	int rows = image.rows;
	int cols = image.cols;
	
	for (int i = 0; i < rows; i++)
	{
		for (int j = 0; j < cols; j++)
		{
			if ((int)image.at<uchar>(i, j) > 200)
			{
				image.at<uchar>(i, j) = 255;
			}
			else
			{
				image.at<uchar>(i, j) = 0;
			}
		}
	}
	//Copy image
	Mat dst_temp = image;
	Mat mask=image.clone();
	for (int i = 0; i < image.rows; i++)
	{
		for (int j = 0; j < image.cols; j++)
		{
			mask.at<uchar>(i, j) = 0;
		}
	}
	namedWindow("src", 1);
	imshow("src", image);
	bool flag = true;
	while(flag)
	{
		flag = false;
		int count = 0;
		for (int i = 1; i < rows - 1; i++)
		{
			for (int j = 1; j < cols - 1; j++)
			{
				if (image.at<uchar>(i, j) == 0)
					continue;
				if (Judge_Condition1(image, i, j) == 1)
					continue;
				if (Judge_Condition2(image, i, j) == 0)
					continue;
				if (Judge_Condition3(image, i, j) != 1)
					continue;
				if (Judge_Condition4(mask, image, i, j) == 1)
					continue;
				if (Judge_Condition5(mask, image, i, j) == 1)
					continue;
				mask.at<uchar>(i, j) = 1;
				count++;
			}
		}
		if (count)
		{
			for (int i = 0; i < mask.rows; i++)
			{
				for (int j = 0; j < mask.cols; j++)
				{
					if (mask.at<uchar>(i, j) == 1)
						image.at<uchar>(i, j) = 0;
				}
			}
			flag = true;
			/*************Reset the mark after one traversal*******************/
			for (int i = 0; i < image.rows; i++)
			{
				for (int j = 0; j < image.cols; j++)
				{
					mask.at<uchar>(i, j) = 0;
				}
			}
		}
	}
	
	
	namedWindow("dst", 1);
	imshow("dst", image);
	waitKey(0);
	return 0;
}
 
int Judge_Condition1(Mat &image, int i, int j)//Four neighborhood points are not all 1
{
	if (((int)image.at<uchar>(i + N[0].x, j + N[0].y) == 0 )&&
		((int)image.at<uchar>(i + N[2].x, j + N[2].y) == 0 )&&
		((int)image.at<uchar>(i + N[4].x, j + N[4].y) == 0 )&&
		((int)image.at<uchar>(i + N[6].x, j + N[6].y) == 0))
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
 
int Judge_Condition2(Mat &image, int i, int j)
{
	int sum = 0;
	sum = (int)image.at<uchar>(i + N[0].x, j + N[0].y) +
		(int)image.at<uchar>(i + N[1].x, j + N[1].y) +
		(int)image.at<uchar>(i + N[2].x, j + N[2].y) +
		(int)image.at<uchar>(i + N[3].x, j + N[3].y) +
		(int)image.at<uchar>(i + N[4].x, j + N[4].y) +
		(int)image.at<uchar>(i + N[5].x, j + N[5].y) +
		(int)image.at<uchar>(i + N[6].x, j + N[6].y) +
		(int)image.at<uchar>(i + N[7].x, j + N[7].y);
	if (sum >= 510)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
 
int Judge_Condition3(Mat &image, int i, int j)
{
	int neighbor[8] = { 0 };
	for (int k = 0; k < 8; k++)
	{
		neighbor[k] = (int)image.at<uchar>(i + N[k].x, j + N[k].y) == 0 ? 1 : 0;
	}
	int count = neighbor[0] - (neighbor[0] & neighbor[1] & neighbor[2]);
	count += neighbor[2] - (neighbor[2] & neighbor[3] & neighbor[4]);
	count += neighbor[4] - (neighbor[4] & neighbor[5] & neighbor[6]);
	count += neighbor[6] - (neighbor[6] & neighbor[7] & neighbor[0]);
	return count;
 
}
 
int Judge_Condition4(Mat &mask, Mat &image, int i, int j)
{
	if (mask.at<uchar>(i - 1, j) == 1)
	{
		image.at<uchar>(i - 1, j) = 0;
		if (Judge_Condition3(image, i, j) != 1)
		{
			image.at<uchar>(i - 1, j) = 255;
			return 1;
		}
	}
}
 
int Judge_Condition5(Mat &mask, Mat &image, int i, int j)
{
	if (mask.at<uchar>(i, j - 1) == 1)
	{
		image.at<uchar>(i, j - 1) = 0;
		if (Judge_Condition3(image, i, j) != 1)
		{
			image.at<uchar>(i, j - 1) = 255;
			return 1;
		}
	}
}

2, Calculate the inclination of the ice water channel

2.1 method: line segment fitting and Hough transform

2.1.1 principle:

The central skeleton of the ice water channel is fitted by line segments, that is, the whole skeleton is divided into several line segments similar to a straight line. The slope of the line segment, that is, the inclination of the ice channel, is calculated by Hough transform.
Refer to the original text (opencv calculation angle) link: link

3, Calculate the distance between ice channels

method:

Similarly, the skeleton of the ice water channel is fitted by the line segment to determine that the center point of the corresponding line segment is ice
Location of the center point of the water channel. Calculate the distance between the center point of each ice water channel and the center point of other ice water channels, and find the shortest distance, that is, the distance between the ice water channel and its adjacent ice water channel. Calculate the arithmetic mean of the distance between all adjacent ice channels as the average distance of adjacent ice channels in the image.

4, Calculate the length of the ice channel

method:

Cunningham [2] provided three measurements of the length of ice water channel when calculating the length of ice water channel
The length of the main diagonal, the skeleton length of the ice water channel and the total length of the ice water channel. In this paper, the length of the main diagonal is used as the distance between the two farthest ends of the connecting skeleton, the length of the inter ice waterway skeleton is the distance between the ends of the connecting skeleton along the skeleton, and the total length of the inter ice waterway is the length of the skeleton plus the length of the branch. Since the branch of the ice water channel has little impact on the ice water channel, the length of the main diagonal is used to represent the length of the ice water channel.

Reference code link: link

Tags: OpenCV image processing

Posted on Sat, 18 Sep 2021 03:36:55 -0400 by qwave