問題描述
===已解決===
感謝您的建議和意見.通過研究 Beginning Python Visualization 一書(第 9 章 - 圖像處理)中給出的 flood_fill 算法) 我已經實現了我想要的.我可以計算對象,獲取每個對象的封閉矩形(因此是高度和寬度),最后可以為每個對象構造 NumPy 數組或矩陣.
Thanks for your suggestions and comments. By working on the flood_fill algorithm given in Beginning Python Visualization book (Chapter 9 - Image Processing) I have implemented what I have wanted. I can count the objects, get enclosing rectangles for each object (therefore height and widths), and lastly can construct NumPy arrays or matrices for each of them.
雖然它不是一種優化的方法,但它可以滿足我的需求.我使用的源代碼 (lab2.py) 和 png 文件 (lab2-particles.png) 已放在 http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450.
Although it is not an optimized approach it does what I want. The source code (lab2.py) and the png file (lab2-particles.png) that I use have been put under http://code.google.com/p/ccnworks/source/browse/#svn/trunk/AtSc450.
您需要安裝 NumPy 和 PIL,并使用 matplotlib 來查看直方圖.代碼的核心位于 objfind 函數中,主要的遞歸對象搜索動作發生在該函數中.
You need NumPy and PIL installed, and matplotlib to see the histogram. Core of the code lies within the objfind function where the main recursive object search action occurs.
進一步更新:
SciPy 的 ndimage.label() 也完全符合我的要求.
SciPy's ndimage.label() does exactly what I want, too.
為 NumPy 和 SciPy 郵件列表中的 David-Warde Farley 和 Zachary Pincus 歡呼:)
Cheers for David-Warde Farley and Zachary Pincus from the NumPy and SciPy mailing-lists for pointing this right into my eyes :)
=============
你好,
我有一張圖像,其中包含由粒子光譜儀測量的冰粒子的陰影.我希望能夠識別每個對象,以便以后可以在計算中進一步分類和使用它們.
I have an image that contains the shadows of ice particles measured by a particle spectrometer. I want to be able to identify each object, so that I can later classify and use them further in my calculations.
本質上,我愿意做的是簡單地實現一個模糊選擇工具,在這里我可以簡單地選擇每個實體.
In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.
我怎樣才能輕松解決這個問題?(最好使用 Python)
How could I easily solve this problem? (Preferably using Python)
謝謝.
注意:在我的問題中,我將每個特定的連接像素稱為對象或實體.我打算提取它們并創建 NumPy 數組表示,如下所示.(這里我使用左上角的對象;如果存在像素,則使用 1,如果不使用 0.該對象的形狀是 3 x 3,對應的 3 像素高 x 3 像素寬.這些是真實冰粒子在 2D 域上的投影, 假設它們是球形的,等效半徑為 (height+width)/2,之后會進行一些縮放——從像素到實際大小和體積計算)
NOTE: In my question I am referring to each specific connected pixels as objects or entities. My intention to extract them and create NumPy array representations as shown below. (Here I am using the top-left object; if a pixel exist use 1's if not use 0's. This object's shape is 3 by 3 which correspondingly 3 pixel height by 3 pixel width. These are projections of real ice-particles onto 2D domain, under the assumption of their being spherical and equivalent radius is (height+width)/2, and later some scalings --from pixels to actual sizes and volume calculations will follow)
import numpy as np
np.array([[1,1,1], [1,1,1], [0,0,1]])
array([[1, 1, 1],
[1, 1, 1],
[0, 0, 1]])
這是我將要使用的圖片中的一部??分.
Here is a section from the image which I am going to use.
截圖 http://img43.imageshack.us/img43/2327/particles.png
推薦答案
掃描每個方格(例如從左上角、從左到右、從上到下)
Scan every square (e.g. from the top-left, left-to-right, top-to-bottom)
當你擊中一個藍色方塊時:
When you hit a blue square then:
一個.將此方格記錄為新對象的位置
a. Record this square as a location of a new object
b.找到所有其他相鄰的藍色方塊(例如通過查看該方塊的鄰居以及這些鄰居的鄰居等)并將它們標記為同一對象的一部分
b. Find all the other contiguous blue squares (e.g. by looking at the neighbours of this square, and the neighbours of those neighbours, etc.) and mark them as being part of the same object
繼續掃描
當你找到另一個藍色方塊時,在進行第 2 步之前測試它是否是已知對象的一部分;或者,在步驟 2b 中,將任何正方形與對象關聯后擦除它
When you find another blue square, test to see whether it's part of a known object before going to step 2; alternatively in step 2b, erase any square after you've associated it with an object
這篇關于簡單的物體識別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!