Ich muss ein Histogramm dehnen

Ich habe ein Array von BitmapFrames und muss ein Histogramm dehnen. Ich weiß, dass dies anders ist als ein Histogrammausgleich und was das Endergebnis ist ... irgendwie. Das Problem ist, dass ich absolut keine Ahnung habe, was ich tun soll, nachdem ich das Histogramm erhalten habe.

Bisher erstellt mein Code ein Array für das Histogramm, damit ich weiß, wie viele Pixel von jedem Wert ich habe. Aber danach weiß ich nicht, was ich tun soll.

Das ist der Code, den ich bisher habe ... im Moment erstellt er das Histogramm und gleicht dann das Histogramm aus ... was ich NICHT will ... Ich habe nur versucht, mehr über Histogramme zu erfahren

[Cmdlet(VerbsData.ConvertTo, "HistoStretch")]
public class HistoStretchCmdlet : PSCmdlet
{
    private BitmapFrame[] bFrame, outFrame;
    private BitmapSource src;
    private double pixelsize;
    private byte[] pixels, outPixels;
    private byte MAX_VAL;
    private int[] histogram;
    private int cf, start;

    [Parameter(ValueFromPipeline = true,
        ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
    public BitmapFrame[] Bitmap
    {
        get
        {
            return bFrame;
        }
        set
        {
            bFrame = value;
        }
    }

    protected override void ProcessRecord()
    {
        base.ProcessRecord();
        Console.Write("Applying a histogram stretch to the image...\n\n");
        outFrame = new BitmapFrame[bFrame.Length];
        for (int c = 0; c < bFrame.Length; c++)
        {
            MAX_VAL = (byte)((1 << bFrame[c].Format.BitsPerPixel) - 1);
            histogram = new int[MAX_VAL + 1];
            for (int i = 0; i <= MAX_VAL; i++)
            {
                histogram[i] = 0;
            }

            pixelsize = bFrame[c].PixelWidth * bFrame[c].PixelHeight;
            pixels = new byte[(int)pixelsize];
            outPixels = new byte[(int)pixelsize];
            bFrame[c].CopyPixels(pixels,(int)bFrame[c].Width * (bFrame[c].Format.BitsPerPixel / 8),0);

            for (int i = 0; i < pixelsize; i++)
            {
                histogram[(int)pixels[i]] = histogram[(int)pixels[i]] + 1;
            }
            for (int i = 0; i <= MAX_VAL; i++)
            {
                Console.Write("{0}: {1}\n", i, histogram[i]);
            }
            for (int i = 0; i <= MAX_VAL; i++)
            {
                if (histogram[i] >= 1)
                {
                    start = i;
                    break;
                }
            }

            for (int i = 0; i < pixelsize; i++)
            {
                cf = 0;
                for (int g = 0; g <= MAX_VAL; g++)
                {
                    cf += histogram[g];
                    if (g == pixels[i])
                    {
                        break;
                    }
                }
                outPixels[i] = (byte)(cf * (MAX_VAL / pixelsize));
            }

            src = BitmapSource.Create(bFrame[c].PixelWidth, bFrame[c].PixelHeight, bFrame[c].DpiX, bFrame[c].DpiY,
                bFrame[c].Format, bFrame[c].Palette, outPixels, (int)(bFrame[c].Width * (bFrame[c].Format.BitsPerPixel / 8)));
            outFrame[c] = BitmapFrame.Create(src);
        }
        WriteObject(outFrame);
    }
}

So sollten die Histogramme laut meinem Lehrer aussehen:

http://www.fileden.com/files/2009/8/18/2547657/histostretch.PNG

Ich habe den obigen Code eingegeben ... und ein glattes schwarzes Bild erhalten. Hier ist mein Code:

outFrame = new BitmapFrame[bFrame.Length];
        for (int c = 0; c < bFrame.Length; c++)
        {
            MAX_VAL = (byte)((1 << bFrame[c].Format.BitsPerPixel) - 1);
            histogram = new int[MAX_VAL + 1];
            for (int i = 0; i <= MAX_VAL; i++)
            {
                histogram[i] = 0;
            }

            pixelsize = bFrame[c].PixelWidth * bFrame[c].PixelHeight;
            pixels = new byte[(int)pixelsize];
            outPixels = new byte[(int)pixelsize];
            bFrame[c].CopyPixels(pixels,(int)bFrame[c].Width * (bFrame[c].Format.BitsPerPixel / 8),0);
            max = pixels[0];
            min = pixels[0];

            for (int i = 0; i < pixelsize; i++)
            {
                histogram[(int)pixels[i]] = histogram[(int)pixels[i]] + 1;
                if((int)pixels[i] > max)
                    max = pixels[i];
                if((int)pixels[i] < min)
                    min = pixels[i];
            }

            dynamic = max - min;

            for (int i = 0; i < pixelsize; i++)
            {
                outPixels[i] = (byte)(((pixels[i] - min) / dynamic) * MAX_VAL);
            }

Antworten auf die Frage(3)

Ihre Antwort auf die Frage