Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I managed to draw the histogram by referring the following link
http://trompelecode.com/blog/2012/04/how-to-create-an-image-histogram-using-csharp-and-wpf/

I drawn input histogram and output histogram i.e after performing the image enhancement operations

Now I want to plot cumulative histogram curve showing the difference in original image pixel and change in pixel after
adjustments like image enhancement operations...

I am referrring following link
http://azzlsoft.com/tag/histogram-equalization/ link

facing problem in the follow code snippet

for (int pixelIndex = 0;
pixelIndex < grayscale.Pixels.Length;
pixelIndex++)
{
byte intensity = (byte)(grayscale.Pixels[pixelIndex] & 0xFF) ;
histogramData[intensity]++;
}
I am not getting the intensity value as writablebitmap grayscale not finding .Pixels[pixelIndex] methode

thanks in advance.... Smile | :)
Posted
Updated 10-Sep-14 23:16pm
v3
Comments
George Jonsson 10-Sep-14 4:54am    
Is your problem to calculate or to draw the cumulative histogram?
vdeo1 10-Sep-14 8:16am    
calulate the value of cumulative graph..
Member 13341679 29-Sep-17 6:50am    
Hi vdeo1, can you please give me the codes to draw the histogram of a bitmap image ?
mail: shubhakantas@gmail.com

Well, if you are working on an image the intensity values for the pixels will have a certain frequency.
10 pixels will have the intensity value of 0, 25 pixels the value of 1, etc.
The cumulative frequency is the sum of the previous frequencies including the current intensity

So you will have a table like this:

Intensity Frequency Cumulative Frequency Calculation
0 10 10 0 + 10
1 25 35 10 + 25
2 30 65 35 + 30
3 35 100 65 + 35
4 30 130 100 + 30
etc.
 
Share this answer
 
Comments
vdeo1 11-Sep-14 2:50am    
On which parameters the frequency is defined/decided or we take the frequency randomly??
I just gone through the follw link
http://azzlsoft.com/tag/histogram-equalization/

But I am not getting grayscale.Pixels[pixelIndex] so cant getting the intensity
George Jonsson 11-Sep-14 2:57am    
Ehrm, you state in your question that you already have the histogram.
Hence, I showed how to calculate the cumulative frequency from an existing histogram.
What have you done so far?
vdeo1 11-Sep-14 4:27am    
I managed to get the histogram by referring the following link
http://trompelecode.com/blog/2012/04/how-to-create-an-image-histogram-using-csharp-and-wpf/

I drawn input histogram and output histogram i.e after performing the image enhancement operations
Now I want to plot curve showing the difference in original image pixel and change in pixel after adjustments like image enhancement operations...
George Jonsson 11-Sep-14 4:35am    
So in what part of your code are you stuck?
vdeo1 11-Sep-14 4:43am    
On http://azzlsoft.com/tag/histogram-equalization/ link

for (int pixelIndex = 0;
pixelIndex < grayscale.Pixels.Length;
pixelIndex++)
{
byte intensity = (byte)(grayscale.Pixels[pixelIndex] & 0xFF) ;
histogramData[intensity]++;
}
I am not getting the intensity value as writablebitmap grayscale not finding .Pixels[pixelIndex] methode
int[] histogramData = new int[256];
WriteableBitmap writeableBmp;
System.Drawing.Bitmap bitmap;
using (MemoryStream outStream = new MemoryStream())
{
writeableBmp = new writeableBitmap(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions()));
}


int[] a = new int[img.Width * img.Height];
for (int pixelIndex = 1; pixelIndex < 256; pixelIndex++)
{
writeableBmp.CopyPixels(a, 1680, pixelIndex);
}

for (int pixelIndex = 1; pixelIndex < img.Width * img.Height; pixelIndex++)
{

byte intensity = (byte)(a.ElementAt(pixelIndex) & 0xFF);
histogramData[intensity]++;
}


for (int intensity = 1; intensity < 256; intensity++)
{
//now we just add the current probability
//to the previous CDF
cumulativeDistributionFunction[intensity] = ((histogramData[intensity]) / img.Width * img.Height) + cumulativeDistributionFunction[intensity - 1];
}
//curve = cumulativeDistributionFunction;
curve = ConvertToPointCollection(cumulativeDistributionFunction);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900