ImageStatistics.cs
Description du code
ImageStatistics.cs est un fichier du projet PhotoBrol.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/photobrol/.
Projet PhotoBrol :
Editeur d'images en CSharp.
Code source ou contenu du fichier
Code c# (ImageStatistics.cs) (300 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Drawing.Imaging; using System.Drawing; using be.gaudry.model.math; using be.gaudry.model.config; using be.gaudry.model.drawing.colors.converter; namespace be.gaudry.photobrol.model.image { /// <summary> /// Gather statistics about the image in RGB color space /// </summary> /// /// <remarks></remarks> /// public class ImageStatistics { private Histogram red; private Histogram green; private Histogram blue; private Histogram gray; private Histogram redWithoutBlack; private Histogram greenWithoutBlack; private Histogram blueWithoutBlack; private Histogram grayWithoutBlack; private int pixels; private int pixelsWithoutBlack; private bool grayscale; /// <summary> /// Histogram of red channel /// </summary> /// public Histogram Red { get { return red; } } /// <summary> /// Histogram of green channel /// </summary> /// public Histogram Green { get { return green; } } /// <summary> /// Histogram of blue channel /// </summary> /// public Histogram Blue { get { return blue; } } /// <summary> /// Histogram of gray channel (intensities) /// </summary> /// public Histogram Gray { get { return gray; } } /// <summary> /// Histogram of the channel excluding black pixels /// </summary> /// public Histogram RedWithoutBlack { get { return redWithoutBlack; } } /// <summary> /// Histogram of green channel excluding black pixels /// </summary> /// public Histogram GreenWithoutBlack { get { return greenWithoutBlack; } } /// <summary> /// Histogram of blue channel excluding black pixels /// </summary> /// public Histogram BlueWithoutBlack { get { return blueWithoutBlack; } } /// <summary> /// Histogram of gray channel (intensities) channel excluding black pixels /// </summary> /// public Histogram GrayWithoutBlack { get { return grayWithoutBlack; } } /// <summary> /// Total pixel count of the image /// </summary> /// public int PixelsCount { get { return pixels; } } /// <summary> /// Total pixel count of the image excluding black pixels /// </summary> /// public int PixelsCountWithoutBlack { get { return pixelsWithoutBlack; } } /// <summary> /// Value wich specifies if the image is color or grayscale /// </summary> /// public bool IsGrayscale { get { return grayscale; } } /// <summary> /// Initializes a new instance of the <see cref="ImageStatistics"/> class /// </summary> /// /// <param name="image">Image to gather statistics about</param> /// /// <remarks>24 bit per pixel or 8 bit indexed (grayscale) images /// are supported only.</remarks> /// public ImageStatistics(Bitmap image) { PixelFormat fmt = (image.PixelFormat == PixelFormat.Format8bppIndexed) ? PixelFormat.Format8bppIndexed : PixelFormat.Format24bppRgb; // lock bitmap data BitmapData imageData = image.LockBits( ImageLockMode.ReadOnly, fmt); // gather statistics ProcessImage(imageData); // unlock image image.UnlockBits(imageData); "AForge.NET", this.ToString(), "http://aforge.googlecode.com/svn/trunk/Sources/", "Informations générales sur le traitement d'images" ) ); } /// <summary> /// Initializes a new instance of the <see cref="ImageStatistics"/> class /// </summary> /// /// <param name="imageData">Image data to gather statistics about</param> /// /// <remarks>24 bit per pixel or 8 bit indexed (grayscale) images /// are supported only.</remarks> /// public ImageStatistics(BitmapData imageData) { ProcessImage(imageData); "AForge.NET", this.ToString(), "http://aforge.googlecode.com/svn/trunk/Sources/", "Informations générales sur le traitement d'images" ) ); } /// <summary> /// Gather statistics about specified image /// </summary> /// /// <param name="imageData">Image data</param> /// private void ProcessImage(BitmapData imageData) { // get image dimension int width = imageData.Width; int height = imageData.Height; pixels = pixelsWithoutBlack = 0; // check pixel format if (grayscale = (imageData.PixelFormat == PixelFormat.Format8bppIndexed)) { // alloc arrays byte value; int offset = imageData.Stride - width; // do the job unsafe { byte* p = (byte*)imageData.Scan0.ToPointer(); // for each pixel for (int y = 0; y < height; y++) { // for each pixel for (int x = 0; x < width; x++, p++) { // get pixel value value = *p; g[value]++; pixels++; if (value != 0) { gwb[value]++; pixelsWithoutBlack++; } } p += offset; } } // create historgram for gray level } else { // alloc arrays byte rValue, gValue, bValue; int offset = imageData.Stride - width * 3; // do the job unsafe { byte* p = (byte*)imageData.Scan0.ToPointer(); // for each line for (int y = 0; y < height; y++) { // for each pixel for (int x = 0; x < width; x++, p += 3) { // get pixel values rValue = p[RGB.R]; gValue = p[RGB.G]; bValue = p[RGB.B]; r[rValue]++; g[gValue]++; b[bValue]++; pixels++; if ((rValue != 0) || (gValue != 0) || (bValue != 0)) { rwb[rValue]++; gwb[gValue]++; bwb[bValue]++; pixelsWithoutBlack++; } } p += offset; } } // create histograms } } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732796468 28/11/2024 13:21:08 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-photobrol-source-rf-model/Image/ImageStatistics.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.