MVTB 2 migration guide: unfinished draft (for consideration) and discrepancies found
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- numpy, opencv, python
- Lĩnh vực
- computer-vision, documentation
Hướng nghiên cứu
Start with the unfinished migration draft in the issue and inspect the Image.threshold implementation and docstring, checking the reported behavior in a clean OpenCV 5.0 environment. Resolve the open decisions, complete or remove the unfinished sections, and publish the result under docs/source/migration with the documented threshold return behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Status: incomplete draft, for consideration. Not a polished design. This is an unfinished set of notes on v1 to v2 changes, written about 6 months ago and parked here from an untracked file (#45). It is not a published migration guide and nothing here is decided.
Why
There is no migration page in the docs, and 2.x is released, so users coming from v1 have nothing telling them what changed (.A / .image to .array, reprs, threshold, Constant signatures, ...).
Fact-check of the draft against 2.4.0 (main at 43c5980c, 2026-10-03)
Run in a clean OpenCV 5.0 venv.
| Claim in the draft | Result |
|---|---|
.array is a read-only property; array_as(dtype) |
confirmed |
img.stats is a dict-valued property; printstats() exists |
confirmed |
binary threshold returns uint8 0/255; as_bool=True gives a bool image |
confirmed |
Image.Constant(value, size=...): size keyword-only, positional Constant(10, 10, 3) rejected |
confirmed |
img.sum, min, max, mean, std, var, median are properties in v2 |
false: they are still methods in 2.4.0 (im.mean() works, type(Image.mean) is a function) |
(not in the draft) threshold('otsu'), 'triangle' and 'percentile' |
return a tuple (Image, threshold_value), not an Image; the threshold docstring says :return: thresholded image |
Things to decide / fix
- Is the scalar-stats-as-properties change intended? If yes, it is not done; if no, remove it from the draft. (Related to
.statsalready being a property.) Image.thresholdreturns a tuple for the algorithm options but its docstring says it returns anImage: fix the docstring, and mention the tuple in the migration notes.- Finish or remove the unfinished parts: the empty "Dtype change" heading, and "Shape functions like
Image.Squares(2, 10, 10)would create..." which stops mid-sentence. - Then publish as a docs page (e.g.
docs/source/migration).
The draft, verbatim
MIGRATION.md (unfinished, as found)
Migration to MVTB 2
Image object
Access to encapsulated pixel data
The Image object keeps a private reference to the numpy array that holds the pixel data. This array should not be
changed directly since it may invalidate the metadata in the object itself.
The private reference was previously either .A or .image. The former is too cryptic and the latter
confusing since it returns an ndarray not an Image.
For v2 this is now .array. It's a read-only property. You can use the referenced array but do not mutate it.
To get an ndarray of a particular type use .array_as(dtype) where dtype is a string or a np datatype.
Dtype change
Reprs
In v1 the str methods were often quite verbose, nicely formatted multiline displays. Some even
displayed tables using ansitable. Most repr methods just called str which is poor practice,
a repr should be concise and single line and ideally be sufficient to recreate the object.
In v2, __repr__s now conform to that model. This means that the old workflow
>>> mvtb_method(...)
would display a verbose response. Now you just get the cryptic version.
Image.threshold()
Image.threshold(t, opt) where t is the threshold that could be a numeric threshold or a string specifying
an algorithm for choosing the threshold. This is modeled on cv.threshold which returns an image the same
type as the source. A bug meant that for floating point images the result would comprise 0 and inf values.
The algorithms for choosing a threshold, otsu and triangle, are limited to uint8/16 and uint8 pixels respectively.
A binary threshold of a floating image should be a boolean image not a float. However boolean images are
not well received by OpenCV, so the decision was made to return uint8 image with pixels as 0 (false) and
255 (true) for the binary threshold case.
Changes:
-
for binary and binary_inv case the return value will always be uint8
-
the as_bool option will return a bool image
-
Otsu and triangle have been implemented from scratch using numpy and handle int or float images
-
a new 'percentile' option has been added
>>> img.threshold(5).print() >>> img.threshold('otsu') >>> img.threshold('percentile', p=90)
Image constants
Image.Constant(10, 10, 3) would create a 10x10 image containing pixel values of 3. It is not particularly
informative when read. It could also be written as Image.Constant(w=10, h=10, value=3) which is not much better.
Worse it could be written as Image.Constant((10,10), 3) or Image.Constant(w=(10,10), value=3).
Too many options, and arguably the constant value should come first.
Shape functions like Image.Squares(2, 10, 10) would create...
All these functions now have the following keyword arguments, they cannot be positional.
size: tuplea tuple either (W,H) or (W,H,C)dtype: str | Dtypea datatype specifier as either a string or an np.dtypecolororder: strspecifying the color order of a multi-channel imagelike: Imagewhere the image sets the defaults for size, dtype and colororder, the options above will override those
The only positional arguments would the ones specific to the method.
Other
Image.stats
Image.stats is now a property (dictionary-valued), not a method.
- v1:
img.stats() - v2:
img.stats - formatted console output:
img.printstats()
Whole-image scalar statistics are now properties as well:
- v1:
img.sum(),img.min(),img.max(),img.mean(),img.std(),img.var(),img.median() - v2:
img.sum,img.min,img.max,img.mean,img.std,img.var,img.median
Related: #45
- Ngôn ngữ chính
- Python
- Star
- 223
- Fork
- 30
- Merge trung bình
- 1 giờ 4 phút
- Pull request đã merge (30 ngày)
- 9
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của petercorke/machinevision-toolbox-python
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
petercorke/machinevision-toolbox-python#125 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
petercorke/machinevision-toolbox-python#119 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
petercorke/machinevision-toolbox-python#117 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Remaining bare `except:` / swallowed exceptions in tests/ and src/ (Codacy + hidden failures)Đang mởtech-debt
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
petercorke/machinevision-toolbox-python#115 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tech-debt
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
petercorke/machinevision-toolbox-python#113 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của petercorke/machinevision-toolbox-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Clean up dependabot noiseĐang mởTask
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
war-and-code/dircue#200 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày