Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

python - How to get the minimum and maxmum number from a series of numbers?

I'm having a hard time cropping the image by using python. I have a series of numbers that represent x,y coordinates on an image. I was trying to crop a rectangle section from the image based on the minimum and the maximum number of coordinates.

For example, here are the x,y coordinates: 1900,199 1500,155, 1200,120 1000,100

The min and max for x are 1000 and 1900, and the min and max for y are 100 and 199 respectively. How can I crop the image based on that?

I'm fairly new to python and not really sure what would be a proper way to do this. Please help! Thank you a lot!!

Here is the original series of x,y coordinates:

1653,146 1651,148 1642,148 1642,166 1640,169 1626,169 1624,166 1624,164 1603,164 1601,162 1601,148 1548,148 1546,150 1546,155 1544,157 1544,166 1541,169 1539,169 1537,166 1471,166 1468,164 1468,157 1466,155 1464,155 1462,153 1372,153 1372,155 1370,157 1363,157 1363,164 1361,166 1297,166 1295,169 1260,169 1256,164 1213,164 1210,166 1167,166 1165,164 1165,162 1162,159 1160,159 1158,157 1151,157 1149,155 1114,155 1112,153 1112,150 1110,148 1062,148 1057,153 1053,153 1050,155 1046,155 1046,194 1048,196 1048,264 1094,264 1096,267 1142,267 1144,264 1151,264 1155,260 1165,260 1167,262 1167,292 1210,292 1210,264 1213,262 1215,262 1217,260 1256,260 1260,255 1263,255 1265,258 1329,258 1331,255 1366,255 1366,253 1368,251 1384,251 1391,258 1393,258 1395,260 1452,260 1455,262 1477,262 1480,264 1480,276 1482,276 1484,278 1535,278 1537,276 1537,264 1539,262 1596,262 1599,260 1612,260 1615,262 1697,262 1699,260 1701,260 1704,258 1706,258 1708,255 1708,217 1704,217 1701,214 1701,198 1699,196 1699,194 1701,191 1701,150 1697,146

question from:https://stackoverflow.com/questions/65907915/how-to-get-the-minimum-and-maxmum-number-from-a-series-of-numbers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
s = "1653,146 1651,148 1642,148 1642,166 1640,169 1626,169 1624,166 1624,164 1603,164 1601,162 1601,148 1548,148 1546,150 1546,155 1544,157 1544,166 1541,169 1539,169 1537,166 1471,166 1468,164 1468,157 1466,155 1464,155 1462,153 1372,153 1372,155 1370,157 1363,157 1363,164 1361,166 1297,166 1295,169 1260,169 1256,164 1213,164 1210,166 1167,166 1165,164 1165,162 1162,159 1160,159 1158,157 1151,157 1149,155 1114,155 1112,153 1112,150 1110,148 1062,148 1057,153 1053,153 1050,155 1046,155 1046,194 1048,196 1048,264 1094,264 1096,267 1142,267 1144,264 1151,264 1155,260 1165,260 1167,262 1167,292 1210,292 1210,264 1213,262 1215,262 1217,260 1256,260 1260,255 1263,255 1265,258 1329,258 1331,255 1366,255 1366,253 1368,251 1384,251 1391,258 1393,258 1395,260 1452,260 1455,262 1477,262 1480,264 1480,276 1482,276 1484,278 1535,278 1537,276 1537,264 1539,262 1596,262 1599,260 1612,260 1615,262 1697,262 1699,260 1701,260 1704,258 1706,258 1708,255 1708,217 1704,217 1701,214 1701,198 1699,196 1699,194 1701,191 1701,150 1697,146"
s = s.split(' ')
s = [list(map(int, i.split(','))) for i in s]

x = [i[0] for i in s]
y = [i[1] for i in s]

max_X, min_X = max(x), min(x)
max_Y, min_Y = max(y), min(y)

print(max_X, min_X)
print(max_Y, min_Y)
# 1708 1046
# 292 146

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...