How to check a random 3d object surface if is flat in python
Firstly, all lines in 3d correspond to an equation; secondly, all lines in 3d that lie on a particular plane for part of their length correspond to equations that belong to a set of linear equations that share certain features, which you would need to determine. The first thing you should do is identify the four corners of the supposed plane - they will have x, y or z values more extreme than the other points. Then check that the lines between the corners have equations in the set - three points in 3d always define a plane, four points may not. Then you should 'plot' the points of two parallel sides using the appropriate linear equations. All the other points in the supposed plane will be 'on' lines (whose equations are also in the set) that are perpendicular between the two parallel sides. The two end points of a perpendicular line on the sides will define each equation. The crucial thing to remember when determining whether a point is 'on' a line is that it may not be, even if the supposed plane was inputted as a plane. This is because x, y and z values as generated by an equation will be rounded so as correspond to 'real' points as defined by the resolution that the graphics program allows. Therefore you must allow for a (very small) discrepancy between where a point 'should be' and where it actually is - this may be just one pixel (or whatever unit of resolution is being used). To look at it another way - a point may be on a perpendicular between two sides but not on a perpendicular between the other two solely because of a rounding error with one of the two equations. If you want to test for a 'bumpy' plane, for whatever reason, just increase the discrepancy allowed. If you post a carefully worded question about the set of equations for the lines in a plane on math.stackexchange.com someone may know more about it.
I used micro CT (it generates a kind of 3D image object) to evaluate my samples which were shaped like a cone. However the main surface which should be flat can not always be placed parallel to the surface of image stacks. To perform the transform, first of all, I have to find a way to identify the flat surface. Therefore I learnt python to read the image data into numpy array. 
Then I realized that I totally have no clue how to achieve the idea in a mathematical way. 
If you have any idea or any suggestion or even packages would be so appreciated.