gregion.h

来自「一个由Mike Gashler完成的机器学习方面的includes neural」· C头文件 代码 · 共 201 行

H
201
字号
/*	Copyright (C) 2006, Mike Gashler	This library is free software; you can redistribute it and/or	modify it under the terms of the GNU Lesser General Public	License as published by the Free Software Foundation; either	version 2.1 of the License, or (at your option) any later version.	see http://www.gnu.org/copyleft/lesser.html*/#ifndef __GREGION_H__#define __GREGION_H__#include "GImage.h"class GPointerArray;class GStringHeap;class GVideo;class GRegionAjacencyGraph{protected:	GPointerArray* m_pRegions;	GPointerArray* m_pNeighbors;	GStringHeap* m_pHeap;public:	GRegionAjacencyGraph();	virtual ~GRegionAjacencyGraph();	// Creates a new region and returns the region number	int AddRegion();	// Returns the number of regions so far	int GetRegionCount();	// Returns the average pixel color in the specified region	void GetAverageColor(int nRegion, float* pRed, float* pGreen, float* pBlue);	// Returns true if the two specified regions are neighbors	bool AreNeighbors(int nRegion1, int nRegion2);	// Makes the two specified regions neighbors (if they aren't	// already neighbors)	void MakeNeighbors(int nRegion1, int nRegion2);	// Returns the number of ajacencies	int GetAjacencyCount();	// Returns the two regions that are ajacent	void GetAjacency(int nEdge, int* pRegion1, int* pRegion2);};class G2DRegionGraph : public GRegionAjacencyGraph{protected:	GImage* m_pRegionMask;public:	G2DRegionGraph(int nWidth, int nHeight);	virtual ~G2DRegionGraph();	// Toboggans the gradient magnitude image of the provided image to produce a	// list of watershed regions	void MakeWatershedRegions(const GImage* pImage);	// Given a G2DRegionGraph, this merges every region with its closest neighbor to	// form a coarser G2DRegionGraph	void MakeCoarserRegions(G2DRegionGraph* pFineRegions);	// Gets a pointer to the region mask image	GImage* GetRegionMask() { return m_pRegionMask; }	// Specifies which region the given pixel belongs to. The color	// of the pixel is also specified so it can keep track of the	// average color of each region	void SetMaskPixel(int x, int y, GColor c, int nRegion);};class G3DRegionGraph : public GRegionAjacencyGraph{protected:	GVideo* m_pRegionMask;public:	G3DRegionGraph(int nWidth, int nHeight);	virtual ~G3DRegionGraph();	// Toboggans the gradient magnitude image of the provided image to produce a	// list of watershed regions	void MakeWatershedRegions(GVideo* pVideo);	// Given a G3DRegionGraph, this merges every region with its closest neighbor to	// form a coarser G3DRegionGraph	void MakeCoarserRegions(G3DRegionGraph* pFineRegions);	// Gets a pointer to the region mask image	GVideo* GetRegionMask() { return m_pRegionMask; }	// Specifies which region the given pixel belongs to. The color	// of the pixel is also specified so it can keep track of the	// average color of each region. (z is the frame number)	void SetMaskPixel(int x, int y, int z, GColor c, int nRegion);};// Iterates the border of a 2D region by running around the border and reporting// the coordinates of each interior border pixel and the direction to the// edge. It goes in a counter-clockwise direction.class GRegionBorderIterator{protected:	GImage* m_pImage;	unsigned int m_nRegion;	int m_x, m_y, m_endX, m_endY;	int m_direction;	bool m_bOddPass;public:	// The point (nSampleX, nSampleY) should be somewhere in the region	// The image pImage should be a region mask, such that all points	// in the same region have exactly the same pixel value.	GRegionBorderIterator(GImage* pImage, int nSampleX, int nSampleY);	~GRegionBorderIterator();	// If it returns false, the current values are invalid and it's done.	// If it returns true, pX and pY will hold the coordinates	// of an interior border pixel. pDirection will be the direction to	// the edge. 0=right, 1=up, 2=left, 3=down.	bool GetNext(int* pX, int* pY, int* pDirection);protected:	bool Look();	void Leap();};class GRegionAreaIterator{protected:	unsigned int m_nRegion;	int m_left, m_right, m_top, m_bottom, m_x, m_y;	GImage* m_pImage;public:	// The point (nSampleX, nSampleY) should be somewhere in the region	// The image pImage should be a region mask, such that all points	// in the same region have exactly the same pixel value.	GRegionAreaIterator(GImage* pImage, int nSampleX, int nSampleY);	~GRegionAreaIterator();	// If it returns false, the current values are invalid and it's done.	// If it returns true, pX and pY will hold the coordinates	// of a pixel in the region	bool GetNext(int* pX, int* pY);};// This class uses Fourier phase correlation to efficiently find// sub-images within a larger imageclass GSubImageFinder{protected:	int m_nHaystackWidth, m_nHaystackHeight, m_nHaystackX, m_nHaystackY;	struct ComplexNumber* m_pHaystackRed;	struct ComplexNumber* m_pHaystackGreen;	struct ComplexNumber* m_pHaystackBlue;	struct ComplexNumber* m_pNeedleRed;	struct ComplexNumber* m_pNeedleGreen;	struct ComplexNumber* m_pNeedleBlue;	struct ComplexNumber* m_pCorRed;	struct ComplexNumber* m_pCorGreen;	struct ComplexNumber* m_pCorBlue;public:	// pHaystack is the image that will be searched for	// sub-images. Its dimensions do not need to be powers of 2.	GSubImageFinder(GImage* pHaystack);	~GSubImageFinder();#ifndef NO_TEST_CODE	static void Test();#endif // NO_TEST_CODE	// The width and height of pNeedleRect must be powers of 2 and less than	// the dimensions of pHaystack. pNeedleRect specifies the portion of pNeedle	// to search for. pHaystackRect allows you to restrict the range. Note that	// restricting the range does not really improve performance. Also note that	// it's okay for pHaystackRect to range outside of the bounds of pImage.	void FindSubImage(int* pOutX, int* pOutY, GImage* pNeedle, GRect* pNeedleRect, GRect* pHaystackRect);};#endif // __GREGION_H__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?