News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Fast Matrix Flip

Started by guga, April 07, 2017, 03:56:33 AM

Previous topic - Next topic

guga

Hi Marinus.

here are some screenshots of a video plugin i tested using the different Matrix Functions. Working like a charm  :t

VDub, in fact, handles the pitch as you said. And it seems that Pitch, is, in fact, width*4 that i labeled on the functions as "NextScanLine".
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

FORTRANS

Hi,

   I have done some "convolution" code for image processing.
Both in assembly and FORTRAN.  Mostly in the early 1990's.
Code was for Sobel edge detection, sharpening, blurring,
deinterlacing of TV image capture, autocorrelation (image
repair), and so forth.  So it can't be too difficult.

   Also tried FFT image processing about that time.  Trying out
bandpass filtering.  A bit more difficult.  And probably less
successful.

Cheers,

Steve N.

guga

Hi Steve, do you still have the autocorrelation functions for image repairing ? Concerning FFT i ported the Algo to assembly, but it is not optimized yet and did not tested on image processing. Dunno if it will work as expected.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

FORTRANS

Hi,

Quote from: guga on April 22, 2017, 11:04:02 PM
Hi Steve, do you still have the autocorrelation functions for image repairing ?

   Yes, I still have the code.  The TV capture card I was using would
"tear" the last few lines of the image.  The bottom of the image had
lines offset from where they should be.  Run the autocorrelation on
the last good line and the first bad one to find out how far to shift it.
Then repeat for the next lines.  Sort of worked, but too much tweaking
by hand was needed.  Haven't looked at it since then.  Don't think I
have made any TV image captures either.

Regards,

Steve N.

guga

If you have time, can you post the code here to we analyse ?

I would like to see how it works in practice. I have some pdfs explaining about image reconstruction, but got clueless on how to make the proper code for it. It seems too way complex for my head :greenclp:

it is a sort of inpaint algorithm, right ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

Hi guga,

I made a start, is this what you want?
Creative coders use backward thinking techniques as a strategy.

guga

Hi marinus.

yes :) That´s it. Many thanks :)

About transposing. When you transpose width became height and vice-versa, right ? That would explain why my version got crossing lines all over  :greensml:

Not sure what i did wrong. Maybe try to exchange width x height, perhaps will solve.

The pope with an alien was simply hilarious :greenclp: :greenclp: :greenclp:
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

 :biggrin:

Yes, if you have different row and column sizes they need to be switched or else your image is distorted.

This week i'll write an image saver. Is the PNG format OK?
When ready i'll post all the source code.
Because it is lossless, the pixel data will be the same as the original.

How fast are the Matrix manipulations "Timing Result in milliseconds" on your PC?
I'm very curious, bet they are much faster than the CPU code we did.
Creative coders use backward thinking techniques as a strategy.

guga

On My I7  it is:

0074246 for transposing  but the counter keeps changing fast and varies, so it is hard to tell the exact speed. 006xxx to 009xxx for FlipX and FlipY, FLipX-Y


I´ll give a try on the filters i´m testing directly on the vdub plugin. Dunno yet, how to rotate (transpose) the video on vdub. I tried simply exchanging width x height and changing the copied buffer but it is crashing. probably because Vdub is trying to keep the original ratio of the video.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

Found it. On Vdub it seems that the transposing can be done on the structure VDXPixmapLayout. Never used that before. I´ll give a try today to see if i can activate it an use the transposing algorithm we are making onto it.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

FORTRANS

Hi,

Quote from: guga on April 24, 2017, 12:13:01 AM
If you have time, can you post the code here to we analyse ?

   Actually there were at least three versions.  This is the oldest and
simplest version.  As I did not comment at the time (1995) on what
the changes were for, why confuse things.  It also means that this
may not be a working example.

      PROGRAM ALIGNV
C
C     Align the lower scan lines in an image file.  Stuff digitized from my VCR
C  has poor scans at the bottom of the picture.
C  SRN, 16 October 1994
C
C     LSTART = Number of lines to skip before processing.
C     MSHIFT = Maximum shift to look for.
C     NSHIFT = 3 x Maximum shift to look for.
C     LEN    = 3 x picture line length = RGB line length.
C
      PARAMETER ( LEN=684*3, MSHIFT=24, NSHIFT=72, LSTART = 450 )
      CHARACTER  CHAR1*(LEN), CHAR2*(LEN), CHAR3*(LEN)
C
      OPEN (1,FILE='FRAME.RAW',FORM='BINARY')
      OPEN (2,FILE='OUT.RAW',FORM='BINARY')
C
      MINDIF = 0
      MAXDIF = 0
C
        DO 10 LINE=1,LSTART
        READ (1,END=91)  CHAR1
        WRITE (2)  CHAR1
   10   CONTINUE
      LINE = LSTART
C
   15 CONTINUE
      LINE = LINE + 1
      READ (1,END=92)  CHAR2
      CALL AUTO ( CHAR1, CHAR2, K )
      MINDIF = MAX( MINDIF, K )
      MAXDIF = MAX( MAXDIF, K )
      JSTART = MAX( 1, 1+K*3 )
      JEND = MIN ( LEN, LEN+K*3 )
        DO 20 J=JSTART,JEND
        CHAR3(J:J) = CHAR2(J+K*3:J+K*3)
   20   CONTINUE
C
        DO 30 J=1,JSTART-1
        CHAR3(J:J) = CHAR2(J:J)
   30   CONTINUE
        DO 40 J=JEND+1,480
        CHAR3(J:J) = CHAR2(J:J)
   40   CONTINUE
C
      WRITE (2)  CHAR3
      WRITE (*,'(1X,2I5)')  LINE, K
      CHAR1 = CHAR3
      GO TO 15
C
   91 PRINT *, 'PREMATURE END ON FRAME.RAW, LINE', LINE
      GO TO 94
C
   92 PRINT *, 'END ON FRAME.RAW, LINE', LINE
      GO TO 94
C
   94 CONTINUE
      WRITE (*,*) MINDIF, MAXDIF
      STOP
      END
      SUBROUTINE AUTO ( CHAR1, CHAR2, K )
      PARAMETER ( LEN=684*3, MSHIFT=24, NSHIFT=72, LSTART = 450 )
      CHARACTER  CHAR1*(LEN), CHAR2*(LEN)
      INTEGER  INT1(LEN), INT2(LEN), ADIF(-MSHIFT:MSHIFT)
C
        DO 10 I=1,LEN
        INT1(I) = ICHAR( CHAR1(I:I) )
        INT2(I) = ICHAR( CHAR2(I:I) )
   10   CONTINUE
C
        DO 20 I= -MSHIFT,MSHIFT
        ADIF(I) = 0
   20   CONTINUE
C
        DO 30 I=NSHIFT+1,LEN-NSHIFT,3
          DO 30 J = -MSHIFT,MSHIFT
          ADIF(J) = ADIF(J) + ABS( INT1(I)-INT2(I+J) )
          ADIF(J) = ADIF(J) + ABS( INT1(I+1)-INT2(I+J+1) )
   30     ADIF(J) = ADIF(J) + ABS( INT1(I+2)-INT2(I+J+2) )
C
      MINDIF = ABS( ADIF(-MSHIFT) )
      K = -MSHIFT
        DO 40 I= -MSHIFT,MSHIFT
        IF ( ABS( ADIF(I) ) .LT. MINDIF )  THEN
          K = I
          MINDIF = ABS( ADIF(I) )
        END IF
   40   CONTINUE
*     K = -K
      WRITE (*,100)  (I,ADIF(I),I=-MSHIFT,MSHIFT)
      RETURN
  100 FORMAT ( 1X, 49(I3,I7) )
      END


   This looks like an error.  But it isn't used.  Change MAX() to MIN().

      MINDIF = MAX( MINDIF, K )


   I hope you find it interesting if not useful as is.  This looks like
monochrome processing.  The later versions look RGBish.

Quote
it is a sort of inpaint algorithm, right ?

   Not sure what you mean.

Cheers,

Steve N.

guga

Many thanks, Steve. I´m taking a look and trying to understand it.

Inpainting techniques are to you make things like this:

https://en.wikipedia.org/wiki/Inpainting
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

Here are the sources as promised released under the SHARE & ENJOY license.  :biggrin:

This is an example how to use Direct3D9 in 2D mode without all the fancy 3D stuff, for very fast image manipulations.

The matrix calculations are done by the video device.
The results can be saved as images ( all the GDIplus formats ) and the raw bitmap data can by read from memory.
I made a comment in the image saver routine.

EDIT: Made a mistake were to put the comment in de "2D_Image_loader_saver.Asm" to fetch the raw bitmap data.
         uploaded a new zip file with the comment at the correct spot in the source code.
Creative coders use backward thinking techniques as a strategy.

avcaballero

Hello. I get an error when save as png.

Siekmanski

Hi caballero,

And it doesn't save the MatrixImage.png i assume?
Can you trace down where exactly in the code the error occurs?
Creative coders use backward thinking techniques as a strategy.