Bir resim içindeki parçalar hakkında bilgi sahibi olabilmek, benzerlikler ve farklılıkları bulabilmek amacıyla bu çalışma yapılacaktır. Genel olarak kullanılan özellikler aşağıda belirtilmiştir:
Kodlamanın göze çarpan kısımları aşağıda belirtilmiştir:
public
static RegionProperties[] FindRegionsProperties(BinaryPGM _image, int _neighbour)
{
ConnectedComponent CC = new ConnectedComponent(_image, _neighbour);
RegionProperties[] Props = new RegionProperties[CC.LabelCount+1];
byte[][] ImageData = CC.LabeledImage.GetImageDataInMatrixForm();
for (int i = 0; i < Props.Length; i++)
{
Props[i] = new RegionProperties();
Props[i].RegionNumber = i;
}
//Props.Length + 1 ::: 0 pixel for background.it will not used
int[] Area = new
int[Props.Length + 1];
ArrayOperations.InitializeArray(ref Area, 0);
double[] CentroidRow = new
double[Props.Length];
ArrayOperations.InitializeArray(ref CentroidRow, 0);
double[] CentroidColumn = new
double[Props.Length];
ArrayOperations.InitializeArray(ref CentroidColumn, 0);
double[] MRD = new
double[Props.Length];
ArrayOperations.InitializeArray(ref MRD, 0);
double[] VRD = new
double[Props.Length];
ArrayOperations.InitializeArray(ref VRD, 0);
double[] SORM = new
double[Props.Length];
ArrayOperations.InitializeArray(ref SORM, 0);
double[] SOCM = new
double[Props.Length];
ArrayOperations.InitializeArray(ref SOCM, 0);
double[] SOMM = new
double[Props.Length];
ArrayOperations.InitializeArray(ref SOMM, 0);
for (int i = 0; i < ImageData.Length; i++)
{
for (int k = 0; k < ImageData[i].Length; k++)
{
Area[ImageData[i][k]]++;
CentroidColumn[ImageData[i][k]] += k;
CentroidRow[ImageData[i][k]] += i;
}
}
for (int i = 1; i < Props.Length; i++)
{
Props[i].Area = Area[i];
Props[i].CentroidX = CentroidColumn[i] / Props[i].Area ;
Props[i].CentroidY = CentroidRow[i] / Props[i].Area;
}
for (int i = 0; i < ImageData.Length; i++)
{
for (int k = 0; k < ImageData[i].Length; k++)
{
MRD[ImageData[i][k]] += Math.Abs(Props[ImageData[i][k]].CentroidY - i) + Math.Abs(Props[ImageData[i][k]].CentroidX - k);
}
}
for (int i = 1; i < Props.Length; i++)
{
Props[i].MeanRadialDistance = MRD[i] / (_image.Length * _image.Width);
}
for (int i = 0; i < ImageData.Length; i++)
{
for (int k = 0; k < ImageData[i].Length; k++)
{
VRD[ImageData[i][k]] += Math.Pow((Math.Abs(Props[ImageData[i][k]].CentroidY - i) + Math.Abs(Props[ImageData[i][k]].CentroidX - k) - Props[ImageData[i][k]].MeanRadialDistance), 2.0);
SORM[ImageData[i][k]] += Math.Pow(Props[ImageData[i][k]].CentroidY - i, 2.0);
SOCM[ImageData[i][k]] += Math.Pow(Props[ImageData[i][k]].CentroidX - k, 2.0);
SOMM[ImageData[i][k]] += (i - Props[ImageData[i][k]].CentroidY ) * (k - Props[ImageData[i][k]].CentroidX);
}
}
for (int i = 1; i < Props.Length; i++)
{
Props[i].VarianceRadialDistance = VRD[i] / (_image.Length * _image.Width);
}
for (int i = 1; i < Props.Length; i++)
{
Props[i].Circularity2 = Props[i].MeanRadialDistance / Math.Pow(Props[i].VarianceRadialDistance, 0.5);
}
for (int i = 1; i < Props.Length; i++)
{
Props[i].SecondOrderColumnMoment = SOCM[i] / Props[i].Area;
Props[i].SecondOrderRowMoment = SORM[i] / Props[i].Area;
Props[i].SecondOrderMixedMoment = SOMM[i] / Props[i].Area;
}
BinaryPGM BoundaryImage = Morphology.GetBoundaryImage(_image);
BoundaryImage.Save("boundary.pgm");
ConnectedComponent CCBoundary = new ConnectedComponent(BoundaryImage, _neighbour);
CCBoundary.LabeledImage.Save("boundary_props.pgm");
byte[] ImageDataBoundary = CCBoundary.LabeledImage.Data;
for (int i = 1; i < Props.Length; i++)
{
Props[i].Perimeter = ArrayOperations.GetArrayElementCount(ImageDataBoundary, (byte)i);
Props[i].Circularity = (Props[i].Perimeter * Props[i].Perimeter) / Props[i].Area;
}
return Props;
Analiz ve Yorumlar
Bu çalışmanın sonuçları aşağıda belirtilmiştir. Şekil 1'de orijinal resim bulunmaktadır. Şekil 2 de ise parçalara ayrılmış resmin numaralandırılmış hali bulunmaktadır. Orijinal resim, 3X3 lük bir yapılandırma elamanı ile Erosion işlemi uygulanıp, orijinal resimden çıkarıldığında sınırlar bulunmuştur. Sınırların alanı, çevre olarak hesaplanmıştır.
Şekil 1 Region Properties – Orijinal Resim
Şekil 2 Region Properties – Labeled, Numbered
Şekil 3 Region Properties – Boundary
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
Area | 560 | 2064 | 2223 | 1920 | 458 | 944 | 1548 | 2556 | 1012 | 1482 | 3136 |
Centroid | 52,5; 27,5 | 146; 58,5 | 244,58; 78,64 | 96,5; 90,5 | 50,5; 95 | 167,67; 138,78 | 255,5; 147,5 | 66; 162,5 | 250,5; 197,5 | 180,5; 207,29 | 71,5; 213,5 |
Mean Radial Distance | 0,11 | 0,66 | 0,79 | 0,7 | 0,07 | 0,21 | 0,42 | 0,87 | 0,22 | 0,4 | 1,44 |
Variance Radial Distance | 1,71 | 16,38 | 23,38 | 21,24 | 0,77 | 3,91 | 8,96 | 22,45 | 3,93 | 8,5 | 52,42 |
Second-Order Row Moment | 16,25 | 213,57 | 158,69 | 533,25 | 44,31 | 80,76 | 78,91 | 222,91 | 97,75 | 115,54 | 85,25 |
Second-Order Column Moment | 133,25 | 133,23 | 327,45 | 47,92 | 29,96 | 104,31 | 192,35 | 185,63 | 68,39 | 127,9 | 800,25 |
Second-Order Mixed Moment | 0 | 0 | 77,23 | 0 | 0 | 12,41 | 0 | 0 | 0 | 0 | 0 |
Circularity2 | 0,08 | 0,16 | 0,16 | 0,15 | 0,08 | 0,11 | 0,14 | 0,18 | 0.11 | 0.14 | 0.2 |
Circularity1 | 0,08 | 16,05 | 36,8 | 21,68 | 19,29 | 32,44 | 20,93 | 19,98 | 16,19 | 15,59 | 20,9 |
Perimeter | 104 | 182 | 286 | 204 | 94 | 175 | 180 | 226 | 128 | 152 | 256 |
Şekil | Yatay dik dörtgen | Kare | Üçgen | Dikey dik dörtgen | Küre | Üçgen | Elips | Küre | Kare | Kare | Yatay dik dörtgen |
Tablo 1 Region Properties Gösterimi
Yukarıdaki tablodan çıkarılacak sonuçlar şunlardır:
- Second-Order Mixed Moment değeri sadece üçgen şeklindeki parçalar için 0 dan farklı çıkmıştır. Üçgen parçaların ayırt edilebilmesi için bu özellik kullanılabilir.
Uygulama
Uygulama, C Sharp(C#) dilinde kodlanmıştır. ComputerVision.exe adlı dosya, çalıştırılabilir halini içermektedir. İşlenecek resimler, bu dosyanın bulunduğu dizine bırakılmalıdır. İşlem sonucunda oluşan rapor dosyaları ve görüntüler, bu dizin altında oluşacaktır. Aşağıda uygulamanın ne şekilde kullanılacağı belirtilmiştir:
C:\cv>ComputerVision.exe
Computer Vision v1.0.0
Mennan Tekbir
Usage:
ComputerVision <operation> <image>
Example:
ComputerVision 3 peppersgray.pgm
Operations :
1 : Connected Components
2 : Erosion(Morphology)
3 : Otsu Thresholding
4 : Region Properties
Press any key to exit...
C:\cv>
Uygulamayı indirmek için...
ComputerVision.zip (442.9 KB)