Page 1 of 1

Decoding Stereograms

Posted: Sun Oct 19, 2014 4:01 pm
by applePi
Hidden image stereograms: in which the depth information is combined into a single image (a stereo pair is no longer visible to the naked eye), or say A Stereogram is an optical illusion of depth created from a 2D image.
look how it works here:
http://www.easystereogrambuilder.com/howTheyWork.aspx
i am trying to imitate the procedure described in this page http://georgik.sinusgear.com/2013/07/12 ... photoshop/
to decode the stereogram, ie to know what the secret picture inside it since i never been able to see the hidden picture from long time ago, in fact i am depressed that i can't see the hidden image inside the stereograms.
if we apply the photoshop procedure using the shark.jpeg stereogram here http://www.vision3d.com/sghidden/shark.html
then this image can be seen
Image
in concise we use 2 layers of the same stereogram, then we choose the blending option to be "Difference" we see the the layer 1 darkened, then we scroll the layer 1 to the right as in the above picture and at some point we see the shark picture
imitating that procedure in purebasic, i can see "ScrollMaterial" function, also "AddMaterialLayer" function, then we scroll the layer 1 slowly we can see very faint traces of the shark. in photoshop we used blending option as "Difference" when we add layer 1 (layer 0 is the original one) but in purebasic what could be in the place of Difference, i see these:
#PB_Material_Add
#PB_Material_Replace
#PB_Material_AlphaBlend
#PB_Material_Modulate

if some one can make the shark appears more thats great.
press left or right arrow to scroll the material layer 1 and try to capture the shark image. use different plans, lighting, etc... may be will work good
use this picture as stereogram http://www.vision3d.com/sghidden/images ... shark.jpeg save it to the same folder as the code. also try other stereograms pictures you may have better luck

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()


Width  = 800
Height = 600

If OpenWindow(0, 0, 0, Width, Height, "left/right arrow keys to scroll material layer 1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(0), 0, 0, Width, Height, 0, 0, 0)
    
    Add3DArchive(".", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Textures",#PB_3DArchive_FileSystem)
    
    Tex0=LoadTexture(#PB_Any,"shark.jpeg")

    Mat=CreateMaterial(#PB_Any,TextureID(Tex0))
    
    Mesh = CreatePlane(#PB_Any, 450, 315, 1, 1, 1, 1)
    Entity=CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Mat),0,0,0)
    RotateEntity(Entity, 90,0,180)
    
Tex1  = LoadTexture(#PB_Any, "shark.jpeg")
AddMaterialLayer(Mat, TextureID(Tex1), #PB_Material_Modulate)

;Mat = CreateMaterial(#PB_Any, TextureID(Tex))
MaterialBlendingMode(Mat, #PB_Material_AlphaBlend)
;MaterialCullingMode(Mat, #PB_Material_NoCulling )       
;SetMaterialColor(Mat, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

    
    Camera=CreateCamera(#PB_Any, 0,0,100,100)
    MoveCamera(Camera, 0, 0, 740)
    CameraLookAt(Camera, 0, 0, 0)
    CameraBackColor(Camera, RGB(55, 55, 55))

    
    Light=CreateLight(#PB_Any, RGB(255,255,255), 0,40,-60)
    
    Rotate=1
    

;DisableMaterialLighting(mat, 1)
    
    ;SetMaterialColor(mat, #PB_Material_AmbientColor, RGB(200, 200, 200))
   ; SetMaterialColor(mat, #PB_Material_SpecularColor, RGB(255, 255, 255))
    ;ScrollMaterial(mat, 0.15, 0, 1)
    
    Repeat
      If ExamineKeyboard()
        
      EndIf
      
      If KeyboardPushed(#PB_Key_Right)
        x.f+0.001
        
        ScrollMaterial(Mat, x, 0, #PB_Material_Fixed  , 1)
      ElseIf KeyboardPushed(#PB_Key_Left)
        x.f-0.001
        ScrollMaterial(Mat, x, 0, #PB_Material_Fixed  , 1)
      EndIf
              

      
        R.f=R+0.5
        ;RotateMaterial(Mat, R, #PB_Material_Fixed,1)
        
        
      RenderWorld()
      FlipBuffers()

    Until WindowEvent() = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    
  EndIf
EndIf
End

Re: Decoding Stereograms

Posted: Sun Oct 19, 2014 9:28 pm
by Pureabc
Very interesting program.

Nice work.

Re: Decoding Stereograms

Posted: Mon Oct 20, 2014 8:56 am
by dige
Very nice! Is it just as easy to create stereograms?

Re: Decoding Stereograms

Posted: Mon Oct 20, 2014 10:19 am
by applePi
dige writes:
Is it just as easy to create stereograms
it seems to me a complex computer procedure to produce as an example the "Single Image Random Dot Stereograms" , one of the algorithms are listed here https://www.cs.sfu.ca/CourseCentral/414 ... ter-94.pdf . one of the descriptions is (each point is computed based of a depth map and projected against a series of random dots)

i only wants to see what is the hidden picture inside the available stereograms, using photoshop procedure gives an idea even it is a poor flat shape, some people saw a real 3D shape after straining their eyes.
after translating the photoshop procedure to purebasic it seems we need something like #PB_Material_Difference option to complement the available #PB_Material_Add,
such that
AddMaterialLayer(Mat, TextureID(Tex1), #PB_Material_Difference)
i may be wrong.
use this stereogram
http://pages.cs.wisc.edu/~glesener/ster ... dSIRDS.jpg
with the code above and we will see a hand (approx) when scrolling the material layer 1 with the above code.

Re: Decoding Stereograms

Posted: Fri Oct 24, 2014 3:59 pm
by applePi
the purpose of this thread is to imitate the photoshop procedure to decode a stereogram picture (look above), but the results was poor , and now i have found that there is "subtract" option for blending materials which is approximately resembles "Difference" option for the material blending in photoshop.
but we should use material script since it is not available in the AddMaterialLayer options which i think implement "colour_op" but here we will use "colour_op_ex" with its extra features.
when you press left arrow key several times (approx 5 seconds) you will get this picture:
Image
which resembles that we got from photoshop
note that when you want to try other stereograms pictures change the name in the material script 2 times and in the (Purebasic code which its purpose only to know its width and height to fit it exactly over the plane)

use the same stereogram picture http://www.vision3d.com/sghidden/images ... shark.jpeg . save the picture and the material file and the code to same folder
matsubtract.material

Code: Select all

material matSubtract
{
    technique
    {
        pass
        {
            texture_unit
            {
                texture shark.jpeg
            }
 
            texture_unit
            {
                texture shark.jpeg
                colour_op_ex subtract src_texture src_current 
               
            }
        }
    }
}
code

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

UsePNGImageDecoder()
UseJPEGImageDecoder()

Width  = 800
Height = 600
#Mat = 122
#image = 123

If OpenWindow(0, 0, 0, Width, Height, "left/right arrow keys to scroll material layer 1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(0), 0, 0, Width, Height, 0, 0, 0)
    
    Add3DArchive(".", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Textures",#PB_3DArchive_FileSystem)
    Parse3DScripts()
    
    GetScriptMaterial(#Mat, "matSubtract")
    
    LoadImage(#image, "shark.jpeg")
    Mesh = CreatePlane(#PB_Any, ImageWidth(#image), ImageHeight(#image) , 1, 1, 1, 1)
    Entity=CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(#Mat),0,0,0)
    RotateEntity(Entity, 90,0,180)
    
;MaterialBlendingMode(#Mat, #PB_Material_AlphaBlend)
;MaterialCullingMode(#Mat, #PB_Material_NoCulling )       
    
    Camera=CreateCamera(#PB_Any, 0,0,100,100)
    MoveCamera(Camera, 0, 0, 740)
    CameraLookAt(Camera, 0, 0, 0)
    CameraBackColor(Camera, RGB(55, 55, 55))

    
    Light=CreateLight(#PB_Any, RGB(255,255,255), 0,40,-60)
    
    Rotate=1
    

    DisableMaterialLighting(#Mat, 1)
    
   ;SetMaterialColor(#Mat, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 255)) 
   ;SetMaterialColor(#Mat, #PB_Material_AmbientColor, RGB(255, 255, 255))
   ;SetMaterialColor(#Mat, #PB_Material_SpecularColor, RGB(255, 255, 255))
   ;SetMaterialColor(#Mat, #PB_Material_SelfIlluminationColor, RGBA(255, 255, 255, 150)) 
   
    ;ScrollMaterial(mat, 0.15, 0, 1)
    
    Repeat
      If ExamineKeyboard()
        
      EndIf
      
      If KeyboardPushed(#PB_Key_Right)
        x.f+0.0005
        
        ScrollMaterial(#Mat, x, 0, #PB_Material_Fixed  , 1)
      ElseIf KeyboardPushed(#PB_Key_Left)
        x.f-0.0005
        ScrollMaterial(#Mat, x, 0, #PB_Material_Fixed  , 1)
      EndIf
              

      
        R.f=R+0.5
        ;RotateMaterial(#Mat, R, #PB_Material_Fixed,1)
        
        
      RenderWorld()
      FlipBuffers()

    Until WindowEvent() = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    
  EndIf
EndIf
End
some stereograms makers
http://www.beroux.com/english/softwares/bigle3d/ freeware
http://www.aolej.com/stereo 30 days trial and have many available textures and shapes and 3d models.

Re: Decoding Stereograms

Posted: Fri Oct 24, 2014 5:31 pm
by Thade
With PureBasic it is not possible as far as I see to render a left cam with adjusted gamma for the red filter, then render the right eye cam with adjusted gamma for the cyan filter within one frame.
This is the method how I managed to create anaglyph pictures with Blitz3D.
If this would work in PB you could manage to see what the eyes see as anaglyph.

Normally we can see this stereogram effect when we focus our view to a point far behing the picture and move that point closer to the picture, then suddenly the scene is 3D.
How about simulating this view to the picture with 2 cams (flickering) right left each frame ... turning the cams until the 3d effect is visble? Then eventually extract the layers.
Just an idea to point you in another direction to solve this ...

Anyway .. great job so far and a good idea to make stereograms visible to those who have problems to see them at all.

Re: Decoding Stereograms

Posted: Sat Oct 25, 2014 8:07 am
by applePi
Thanks Thade for the suggestions, until i read the following docs to know exactly how the single image stereograms works ,it seems to me strange that (in Single Image Stereograms and random dot stereograms) encoding a depth picture inside a texture is a one directional process and can be reversed only by the human 2eyes/brain and in all these long years from 1959 the programmers and the vision scientists are able only to decode it to a 2D flat shape as in the references below to some utilities.
making a stereogram decoder to show a full 3D image is a dream of thousands of people , i think it is either very hard or impossible to make. since it needs to simulate how our brains somehow extract stereo shapes from what appears to be a random dots and lines

Goodies i have found:
1- good online stereogram solver here http://magiceye.ecksdee.co.uk/
but it gives a 2D flat shape like the above PB program, its main program are embeded in the magiceye.js
2- poor online solver here http://www.hidden-3d.com/index.php?id=reveal

additional info:
3- a research project solver http://www.cs.bgu.ac.il/~ben-shahar/Tea ... aGroisman/
it contains source code in matlab ,and samples, again the results the same as above.
it contains also solver.exe but i can't run it, it seems 64 bit program

4- book GPU Gems (online) ,Chapter 41. Real-Time Stereograms : http://http.developer.nvidia.com/GPUGem ... _ch41.html

Creating a Stereogram with GIMP:
5- http://www.gimptalk.com/index.php?/topi ... with-gimp/

Theoretical Aspects of Single Image Stereography:
6- http://www.ixtlan.ru/theory.php#

Re: Decoding Stereograms

Posted: Sat Oct 25, 2014 9:13 pm
by Thade
I made some tests trying to convert Sirds to 3D anaglyphs ... but was not successful yet.
I am interested in 3D of all kind since the 1970s ... so this seems to be a real challenge ... and I think I shall continue to work on it if I have some time for.

Re: Decoding Stereograms

Posted: Thu Mar 17, 2016 9:16 pm
by dobro
Thade wrote:With PureBasic it is not possible as far as I see to render a left cam with adjusted gamma for the red filter, then render the right eye cam with adjusted gamma for the cyan filter within one frame..

look here :
http://www.purebasic.fr/french/viewtopi ... =anaglyphe

Re: Decoding Stereograms

Posted: Fri Mar 18, 2016 12:19 am
by Thade
Thanks, dobro

Looks great after several additional installations from NVidia.
Have not figured out color3D yet - its all black and white - will have a deeper look into it, after I've finished the current project.