問(wèn)題描述
===已解決===
感謝您的建議和意見(jiàn).通過(guò)研究 Beginning Python Visualization 一書(shū)(第 9 章 - 圖像處理)中給出的 flood_fill 算法) 我已經(jīng)實(shí)現(xiàn)了我想要的.我可以計(jì)算對(duì)象,獲取每個(gè)對(duì)象的封閉矩形(因此是高度和寬度),最后可以為每個(gè)對(duì)象構(gòu)造 NumPy 數(shù)組或矩陣.
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.
雖然它不是一種優(yōu)化的方法,但它可以滿(mǎn)足我的需求.我使用的源代碼 (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 來(lái)查看直方圖.代碼的核心位于 objfind 函數(shù)中,主要的遞歸對(duì)象搜索動(dòng)作發(fā)生在該函數(shù)中.
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.
進(jìn)一步更新:
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 :)
=============
你好,
我有一張圖像,其中包含由粒子光譜儀測(cè)量的冰粒子的陰影.我希望能夠識(shí)別每個(gè)對(duì)象,以便以后可以在計(jì)算中進(jìn)一步分類(lèi)和使用它們.
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.
本質(zhì)上,我愿意做的是簡(jiǎn)單地實(shí)現(xiàn)一個(gè)模糊選擇工具,在這里我可以簡(jiǎn)單地選擇每個(gè)實(shí)體.
In essence, what I am willing to do is to simply implement a fuzzy selection tool where I can simply select each entity.
我怎樣才能輕松解決這個(gè)問(wèn)題?(最好使用 Python)
How could I easily solve this problem? (Preferably using Python)
謝謝.
注意:在我的問(wèn)題中,我將每個(gè)特定的連接像素稱(chēng)為對(duì)象或?qū)嶓w.我打算提取它們并創(chuàng)建 NumPy 數(shù)組表示,如下所示.(這里我使用左上角的對(duì)象;如果存在像素,則使用 1,如果不使用 0.該對(duì)象的形狀是 3 x 3,對(duì)應(yīng)的 3 像素高 x 3 像素寬.這些是真實(shí)冰粒子在 2D 域上的投影, 假設(shè)它們是球形的,等效半徑為 (height+width)/2,之后會(huì)進(jìn)行一些縮放——從像素到實(shí)際大小和體積計(jì)算)
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
推薦答案
掃描每個(gè)方格(例如從左上角、從左到右、從上到下)
Scan every square (e.g. from the top-left, left-to-right, top-to-bottom)
當(dāng)你擊中一個(gè)藍(lán)色方塊時(shí):
When you hit a blue square then:
一個(gè).將此方格記錄為新對(duì)象的位置
a. Record this square as a location of a new object
b.找到所有其他相鄰的藍(lán)色方塊(例如通過(guò)查看該方塊的鄰居以及這些鄰居的鄰居等)并將它們標(biāo)記為同一對(duì)象的一部分
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
繼續(xù)掃描
當(dāng)你找到另一個(gè)藍(lán)色方塊時(shí),在進(jìn)行第 2 步之前測(cè)試它是否是已知對(duì)象的一部分;或者,在步驟 2b 中,將任何正方形與對(duì)象關(guān)聯(lián)后擦除它
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
這篇關(guān)于簡(jiǎn)單的物體識(shí)別的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!