Search the web
Sign In
New User? Sign Up
arcondev · Artificial Consciousness Development:
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
My first code release. =)   Message List  
Reply | Forward Message #1408 of 1438 |
In the spirit of open AI development for the good of all, I hereby
present my first code release.

Attached is the source code of my image processor class that attempts to
duplicate the center-surround processing of the human retina.

It can be loaded into a squeak immage. ( www.squeak.org ) and run on
arbitrary immages you file-in using the file viewer.

I found the solution to making it work was to iterate over several
magnification scales.

This approach is supported by the anatomical observation that the three
groups of layers in the lateral geniculate nucleus probably represent
three levels of neural convergance.

To make this code work, use "viewer" to create a script for your input
immage and input the following code. ( the stuff between the hash marks.)

To get profiling information, open a "transcript" window.

This code will run in approximately 1 minute on a medium sized input
immage on a dual 1.2 ghz Athlon.

This code might crash on smaller input images, if so, try reducing the
parameter to "iterationsDo: "

######################

script1

| imageProc delta t1 t2 t3 t4 |
imageProc _ ImageProcessor new.

t1 _ Time millisecondsToRun:
[ imageProc setSource: (self getGraphic). ].

t2 _ Time millisecondsToRun: [
imageProc preProcessBrightness.
delta _ SketchMorph new.
].

"delta form: (imageProc centerSurroundAlt ).
"
t3 _ Time millisecondsToRun: [
imageProc iterationsDo: 7.
].

t4 _ Time millisecondsToRun: [
delta form: (imageProc generateGreyForm).
].

delta openInWorld.

Transcript show: t1;
show: ' ';
show: t2;
show: ' ';
show: t3;
show: ' ';
show: t4;
cr.

######################

----------

'From Squeak3.6 of ''6 October 2003'' [latest update: #5429] on 19 March 2004 at
11:58:12 pm'!
Object subclass: #ImageProcessor
instanceVariableNames: 'theForm theColorArray brightnessArray tempArray width
height scale factor '
classVariableNames: ''
poolDictionaries: ''
category: 'AI-Cybernetic'!

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/14/2004 23:38'!
centerSurround
| formwidth |
formwidth _ theForm width.
1
to: theForm height - 2
do: [:i |
| itfw |
itfw _ i * formwidth.
1 to: formwidth - 2 do: [:j |
| a b center jip jim |
jim _ j + itfw.
center _ jim + 1.
jip _ center + 1.
a _ (brightnessArray at: center - formwidth)
+ (brightnessArray at: jim)
+ (brightnessArray at: jip)
+ (brightnessArray at: center + formwidth).
b _ (brightnessArray at: jim - formwidth)
+ (brightnessArray at: jip - formwidth)
+ (brightnessArray at: jim + formwidth)
+ (brightnessArray at: jip + formwidth).
a _ a * 2 + b / 12 .
a _ (brightnessArray at: center) - a.
tempArray at: center put: ((tempArray at: center)
+ a ) ]].
^ nil.! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 12/5/2003 02:48'!
centerSurroundAlt
| outform formwidth |
formwidth _ theForm width.
outform _ Form extent: formwidth - 2 / 2 @ (theForm height - 3 / 2) depth: 32.
1
to: outform height
do: [:i | 1
to: outform width
do: [:j |
| center surround place |
place _ j * 2 + (i * 2 * formwidth).
center _ (brightnessArray at: place)
+ (brightnessArray at: place + 1)
+ (brightnessArray at: place + formwidth)
+ (brightnessArray at: place + formwidth + 1) / 4.
surround _ (brightnessArray at: place - formwidth - 1)
+ (brightnessArray at: place - formwidth + 2)
+ (brightnessArray at: place + (2 * formwidth) - 1)
+ (brightnessArray at: place + (2 * formwidth) + 2) / 2.
surround _ surround
+ (brightnessArray at: place - formwidth)
+ (brightnessArray at: place - formwidth + 1)
+ (brightnessArray at: place - 1)
+ (brightnessArray at: place + 3)
+ (brightnessArray at: place + formwidth - 1)
+ (brightnessArray at: place + formwidth + 3)
+ (brightnessArray at: place + (2 * formwidth))
+ (brightnessArray at: place + (2 * formwidth) + 1) / 10.
center _ surround - center * 16.
center _ center abs.
outform
colorAt: j @ i
put: (Color gray: center)]].
^ outform! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/19/2004 22:58'!
centerSurroundScaled
1
to: height - 2
do: [:i |
| itw |
itw _ i * width.
1 to: width - 2 do: [:j |
| a b center jip jim |
jim _ j + itw.
center _ jim + 1.
jip _ center + 1.
a _ (brightnessArray at: center - width)
+ (brightnessArray at: jim)
+ (brightnessArray at: jip)
+ (brightnessArray at: center + width).
b _ (brightnessArray at: jim - width)
+ (brightnessArray at: jip - width)
+ (brightnessArray at: jim + width)
+ (brightnessArray at: jip + width).
a _ a * 2 + b / 12 .
a _ (brightnessArray at: center) - a / factor .

self magnifyAndPrint: a toX: j+1 Y: i+1 ]].
^ nil.! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/19/2004 23:08'!
collapseArray
| newArray oldwidth |
scale _ scale bitShift: 1.
factor _ factor + 1.
oldwidth _ width.
width _ width bitShift: -1.
height _ height bitShift: -1.
newArray _ Array new: height * width.
0
to: height - 1
do: [:i |
| iDelta iDeltaOne |
iDelta _ i * 2.
iDeltaOne _ iDelta + 1 * oldwidth.
iDelta _ iDelta * oldwidth.
1
to: width
do: [:j |
| x tj |
tj _ j - 1 * 2 + 1.
x _ (brightnessArray at: tj + iDelta)
+ (brightnessArray at: tj + iDelta + 1)
+ (brightnessArray at: tj + iDeltaOne)
+ (brightnessArray at: tj + iDeltaOne + 1).
x _ x / 4.
newArray at: j + (i * width) put: x]].
brightnessArray _ newArray! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/19/2004 23:08'!
colorblindForm
| outform formwidth |
formwidth _ theForm width.
outform _ Form extent: formwidth @ theForm height depth: 16.
1
to: theForm height
do: [:i | 1
to: theForm width
do: [:j |
| borkedColor yellow |
borkedColor _ theColorArray at: i - 1 * theForm width + j.
yellow _ borkedColor red + borkedColor green / 2.
borkedColor _ Color
r: yellow
g: yellow
b: borkedColor blue.
outform colorAt: j @ i put: borkedColor]].
^ outform! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 1/25/2004 13:26'!
enhanceTexture
| outform formwidth |
formwidth _ theForm width.
outform _ Form extent: formwidth - 2 @ (theForm height - 2) depth: 16.
1
to: outform height
do: [:i | 1
to: outform width
do: [:j |
| a b center jip jim |
jim _ j + (i * formwidth).
center _ jim + 1.
jip _ center + 1.
a _ (brightnessArray at: center - formwidth)
+ (brightnessArray at: jim)
+ (brightnessArray at: jip)
+ (brightnessArray at: center + formwidth).
b _ (brightnessArray at: jim - formwidth)
+ (brightnessArray at: jip - formwidth)
+ (brightnessArray at: jim + formwidth)
+ (brightnessArray at: jip + formwidth).
a _ a * 2 + b / 12.
b _ 2.0 * (brightnessArray at: center).
a _ b - a. "* 3 + 0.5 ."

a < 0.0 ifTrue: [ a _ 0.0 ].
a > 1.0 ifTrue: [ a _ 1.0 ].
outform
colorAt: j @ i
put: (Color gray: a)]].
^ outform! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/15/2004 01:46'!
generateGreyForm
| outform |
outform _ Form extent: (theForm width) @ (theForm height) depth: 32.
1
to: theForm height
do: [:i | 1
to: theForm width
do: [:j | | foo |
foo _ tempArray at: i - 1 * theForm width + j.
foo > 1.0 ifTrue: [ foo _ 1.0 ].
foo < 0.0 ifTrue: [ foo _ 0.0 ].
outform colorAt: j @ i
put: (Color gray: foo)]].
^ outform! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/15/2004 12:36'!
iterationsDo: count

count < 0 ifTrue: [self halt. "usage error" ].
self centerSurround.

2 to: count do: [:i |
self collapseArray.
self centerSurroundScaled.
]. ! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/15/2004 01:34'!
magnifyAndPrint: value toX: x Y: y
| lineBase columnBase |
columnBase _ (x-1) * scale + 1 .
lineBase _ (y-1) * scale * theForm width.
0
to: (scale -1 )
do: [:i |
| lineAdjust |
lineAdjust _ lineBase + (i * theForm width).
0
to: (scale -1 )
do: [:j | tempArray at: (lineAdjust + columnBase + j) put: value
+ (tempArray at: lineAdjust + columnBase + j)]]! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/19/2004 22:57'!
preProcessBrightness
scale _ 1.
factor _ 0.
brightnessArray _ Array new: theColorArray size.
tempArray _ Array new: theColorArray size.
1
to: theColorArray size
do: [:i | brightnessArray at: i put: (theColorArray at: i) brightness.
tempArray at: i put: 0.5 ].
^ brightnessArray! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/15/2004 02:00'!
scale
^ scale. ! !

!ImageProcessor methodsFor: 'as yet unclassified' stamp: 'ATG 3/14/2004 10:57'!
setSource: aForm
theForm _ aForm.
height _ aForm height.
width _ aForm width.
theColorArray _ ColorArray new: height * width.
1
to: height
do: [:i | 1
to: width
do: [:j | theColorArray
at: (i - 1) * width + j
put: (theForm colorAt: j @ i)]]! !


[Non-text portions of this message have been removed]




Sat Mar 20, 2004 5:08 am

al0nz0tg
Online Now Online Now
Send Email Send Email

Forward
Message #1408 of 1438 |
Expand Messages Author Sort by Date

In the spirit of open AI development for the good of all, I hereby present my first code release. Attached is the source code of my image processor class that...
Alan Grimes
al0nz0tg
Online Now Send Email
Mar 20, 2004
5:09 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help