Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
kai  
#1 Posted : Tuesday, January 6, 2004 7:31:00 PM(UTC)
kai

Rank: Member

Groups: Member
Joined: 1/6/2004(UTC)
Posts: 8

dear aurigma team,

first of all, thanks for this fine graphic processing component. its functionality is very impressive.

i´d like to know if it is possible to calculate an avarage color value of all the pixels in an image.

thank you for your answer and keep the good work
creetings from berlin - germany
Fedor  
#2 Posted : Wednesday, January 7, 2004 12:04:00 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
first of all, thanks for this fine graphic processing component. its functionality is very impressive.

thank you for your answer and keep the good work
creetings from berlin - germany


Thank you, it is very pleasant for us :D

i´d like to know if it is possible to calculate an avarage color value of all the pixels in an image.

Unfortunately there is no built-in function to get an average color, however it is not a problem to implement it in a several ways. What is your programming language? I will post a code sample here.
Best regards,
Fedor Skvortsov
kai  
#3 Posted : Wednesday, January 7, 2004 7:10:00 PM(UTC)
kai

Rank: Member

Groups: Member
Joined: 1/6/2004(UTC)
Posts: 8

i´d like to use it within an asp page.
programming language is vb script.
Fedor  
#4 Posted : Wednesday, January 7, 2004 10:00:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Here is a code sample which calculates average color. Before using it, download the latest update of Graphics Mill (version 2.0.311.0 or higher). We have found a bug in GetHistogram method and fixed it.<br><br>View post<br><br>Use this code:<br><br>
Code:
<!-- METADATA TYPE="typelib" UUID="{3CE48541-DE7A-4909-9314-9D0ED0D1CA5A}"-->
<%
Option Explicit

Dim objBitmap
'Create Bitmap object
Set objBitmap = Server.CreateObject("GraphicsMill.Bitmap")

objBitmap.LoadFromFile Server.MapPath("building.jpg")

Dim lngAvgRed, lngAvgGreen, lngAvgBlue
Dim arrHistogram, I, lngAvgColor

'Get histogram for each channel to calculate average
'intensity of an appropriate channel.

'To do it, get sum of elements of histogram multiplied
'on appropriate intensity
arrHistogram=objBitmap.Data.GetHistogram(ChannelRed)
lngAvgRed = 0
For I=0 To 255
	lngAvgRed = lngAvgRed + I * arrHistogram(I)
Next

'After that, normalize this sum on the amount of pixels. 
'Total amount of pixels equals width * height 
lngAvgRed = Round(lngAvgRed / (objBitmap.Data.Width * objBitmap.Data.Height))

'Do the same for green and blue channels
arrHistogram=objBitmap.Data.GetHistogram(ChannelGreen)
lngAvgGreen = 0
For I=0 To 255
	lngAvgGreen = lngAvgGreen + I * arrHistogram(I)
Next
lngAvgGreen = Round(lngAvgGreen / (objBitmap.Data.Width * objBitmap.Data.Height))

arrHistogram=objBitmap.Data.GetHistogram(ChannelBlue)
lngAvgBlue = 0
For I=0 To 255
	lngAvgBlue = lngAvgBlue + I * arrHistogram(I)
Next
lngAvgBlue = Round(lngAvgBlue / (objBitmap.Data.Width * objBitmap.Data.Height))

'After we calculate average intensities of each channel,
'combine them into one RGB color.
lngAvgColor = objBitmap.Color.CreateRgb(lngAvgRed, lngAvgGreen, lngAvgBlue) 

'Display this color. Let's draw the square 30x30 filled with average color 
'we calculated. 
objBitmap.Graphics.Brush.PrimaryColor = lngAvgColor
objBitmap.Graphics.DrawRectangle 10, 10, 30, 30, True, True

objBitmap.SaveToStream Response
%>

Edited by user Thursday, December 20, 2007 6:48:49 PM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.