Jump to content

WIA.Vector resize image


Ascer
 Share

Recommended Posts

Hello,

Do you have any idea to resize Vector graphic using some maths trick?

It's example to create Vector image 10x10px and write A

Local $a10x10 = [ _
1,1,1,1,1,1,1,1,1,1, _
1,1,1,0,0,0,0,1,1,1, _
1,1,0,0,1,1,0,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,0,0,0,0,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,0,0,0,1,1,0,0,0,1, _
1,1,1,1,1,1,1,1,1,1 _
]

Local $oVector = ObjCreate("WIA.Vector.1")

If Not IsObj($oVector) Then
    ConsoleWrite("+++ Error " & @error & " durning create a Vector.object." & @CRLF)
    Exit
EndIf

Local $iBlue = 0xFF0000FF ; ARGB color
Local $iWhite = 0xFFFFFFFF

; adding pixels to vector
For $i = 0 To UBound($a10x10) - 1
    Local $iPixel = $a10x10[$i]
    Local $iColor = $iBlue
    If $iPixel = 0 Then $iColor = $iWhite
    $oVector.Add($iColor)
Next

; create a img 10x10 px
Local $oImg = $oVector.ImageFile(10, 10)

; path to file
Local $sPath = @ScriptDir & "\Vector.bmp"

; delete previous file if exits.
FileDelete($sPath)

; save img to script direction.
$oImg.SaveFile($sPath)

; show result, you have to use 800% size to see effects.
ShellExecute("Vector.bmp")

 

Link to comment
Share on other sites

Take a look into this image. Vector should change like this, now need to write maths algoritm.

                     2x2 px                                                                                           4x4 px

vector.png

Link to comment
Share on other sites

You can scale (resize) the image but I assume you want the vector resized.

Local $a10x10 = [ _
1,1,1,1,1,1,1,1,1,1, _
1,1,1,0,0,0,0,1,1,1, _
1,1,0,0,1,1,0,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,0,0,0,0,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,0,0,0,1,1,0,0,0,1, _
1,1,1,1,1,1,1,1,1,1 _
]

Local $oVector = ObjCreate("WIA.Vector.1")
Local $oImageProcess = ObjCreate("WIA.ImageProcess")

If Not IsObj($oVector) Then
    ConsoleWrite("+++ Error " & @error & " durning create a Vector.object." & @CRLF)
    Exit
EndIf

If Not IsObj($oImageProcess) Then
    ConsoleWrite("+++ Error " & @error & " durning create a ImageProcess.object." & @CRLF)
    Exit
EndIf

Local $iBlue = 0xFF0000FF ; ARGB color
Local $iWhite = 0xFFFFFFFF

; adding pixels to vector
For $i = 0 To UBound($a10x10) - 1
    Local $iPixel = $a10x10[$i]
    Local $iColor = $iBlue
    If $iPixel = 0 Then $iColor = $iWhite
    $oVector.Add($iColor)
Next

; create a img 10x10 px
Local $oImg = $oVector.ImageFile(10, 10)

;scale image
$oImageProcess.Filters.Add($oImageProcess.FilterInfos("Scale").FilterID)
$oImageProcess.Filters(1).Properties("MaximumWidth") = 100
$oImageProcess.Filters(1).Properties("MaximumHeight") = 100
$oImg_Resized = $oImageProcess.Apply($oImg)

; path to file
Local $sPath = @ScriptDir & "\Vector.bmp"

; delete previous file if exits.
FileDelete($sPath)

; save img to script direction.
$oImg_Resized.SaveFile($sPath)

; show result, you have to use 800% size to see effects.
ShellExecute("Vector.bmp")

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I think that not.

It's example of 20x10

Local $a20x10 = [ _
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, _
1,0,1,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1, _
1,0,1,1,1,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1, _
1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1, _
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 _
]

Local $oVector = ObjCreate("WIA.Vector.1")

If Not IsObj($oVector) Then
    ConsoleWrite("+++ Error " & @error & " durning create a Vector.object." & @CRLF)
    Exit
EndIf

Local $iBlack = 0x00000000 ; ARGB color
Local $iWhite = 0xFFFFFFFF

; adding pixels to vector
For $i = 0 To UBound($a20x10) - 1
    Local $iPixel = $a20x10[$i]
    Local $iColor = $iBlack
    If $iPixel = 0 Then $iColor = $iWhite
    $oVector.Add($iColor)
Next

; create a img 10x10 px
Local $oImg = $oVector.ImageFile(20, 10)

; path to file
Local $sPath = @ScriptDir & "\Vector.bmp"

; delete previous file if exits.
FileDelete($sPath)

; save img to script direction.
$oImg.SaveFile($sPath)

; show result, you have to use 800% size to see effects.
ShellExecute("Vector.bmp")

 

Link to comment
Share on other sites

There is a way to get vector size.

Local $oVector = ObjCreate("WIA.Vector.1")

ConsoleWrite("The count of vector before adding is " & $oVector.Count & @CRLF)
ConsoleWrite("Adding 100 items to vector..." & @CRLF)

For $i = 1 To 100
    $oVector.Add($i)
Next

ConsoleWrite("Adding has end, current count of vector is " & $oVector.Count & @CRLF)

You can also find more vectors functions here: https://msdn.microsoft.com/pl-pl/library/windows/desktop/ms630513(v=vs.85).aspx

Link to comment
Share on other sites

Convert the 1D vector into a 2D array, map it to a new 2D array based on scaled and rounded indexes (a nested loop for example) then convert the new 2D array back into a 1D array... Small changes in array size will still look ugly because of the rounding. On larger arrays you could introduce blurring based on the surrounding indexes....

 

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

Well, for quadratic array this works but not for the other non quadratic one.

#include <Array.au3>
Local $a20x10 = [ _
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, _
1,0,1,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1, _
1,0,1,1,1,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1, _
1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1, _
1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1, _
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 _
]

Local $a10x10 = [ _
1,1,1,1,1,1,1,1,1,1, _
1,1,1,0,0,0,0,1,1,1, _
1,1,0,0,1,1,0,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,0,0,0,0,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,1,0,1,1,1,1,0,1,1, _
1,0,0,0,1,1,0,0,0,1, _
1,1,1,1,1,1,1,1,1,1 _
]

Local $oVector = ObjCreate("WIA.Vector.1")
Local $oImageProcess = ObjCreate("WIA.ImageProcess")

If Not IsObj($oVector) Then
    ConsoleWrite("+++ Error " & @error & " durning create a Vector.object." & @CRLF)
    Exit
EndIf

If Not IsObj($oImageProcess) Then
    ConsoleWrite("+++ Error " & @error & " durning create a ImageProcess.object." & @CRLF)
    Exit
EndIf

Local $iBlue = 0x0000FF ; RGB color
Local $iWhite = 0xFFFFFF

Local $fScaleX = 20, $fScaleY = 20, $iUboundX = 20, $iUboundY = 10
Local $aVector_scaled = ScaleVectorArray1D($a20x10, $iUboundY, $iUboundX, $fScaleX, $fScaleY)

; adding pixels to vector
For $i = 0 To UBound($aVector_scaled) - 1
    Local $iPixel = $aVector_scaled[$i]
    Local $iColor = $iBlue
    If $iPixel = 0 Then $iColor = $iWhite
    $oVector.Add($iColor)
Next

; create a img 10x10 px
Local $oImg = $oVector.ImageFile($fScaleX * $iUboundX, $fScaleY * $iUboundY)

; path to file
Local $sPath = @ScriptDir & "\Vector.bmp"

; delete previous file if exits.
FileDelete($sPath)

; save img to script direction.
$oImg.SaveFile($sPath)

; show result, you have to use 800% size to see effects.
ShellExecute("Vector.bmp")


Func ScaleVectorArray1D($aVector1D, $iUboundY, $iUboundX, $iScaleX = 20, $iScaleY = 20)
    Local $aVector2D[$iUboundY][$iUboundX]
    Local $c = 0, $x, $y
    For $y = 0 To UBound($aVector2D) - 1
        For $x = 0 To UBound($aVector2D, 2) - 1
            $aVector2D[$y][$x] = $aVector1D[$c]
            $c += 1
        Next
    Next
    Local $iUB2x = UBound($aVector2D, 2) * $iScaleX, $iUB2y = UBound($aVector2D) * $iScaleY
    Local $aVector1D_new[$iUB2x * $iUB2y], $dx = UBound($aVector2D, 2) / $iUB2x, $dy = UBound($aVector2D) / $iUB2y
    $c = 0
    For $y = 0 To $iUB2y - 1
        For $x = 0 To $iUB2x - 1
            $aVector1D_new[$c] = $aVector2D[$y * $dy][$x * $dx]
            $c += 1
        Next
    Next
    Return $aVector1D_new
EndFunc

 

Working on it... fixed it.

Edited by UEZ
Issue fixed with non quadratic arrays

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@UEZ

Look this example below vectors seems to be amazing.. mmm...

Local $a10x10 = [ _
2,2,2,2,2,2,2,2,2,2, _
2,0,0,0,0,1,1,1,1,2, _
2,0,1,1,1,0,0,0,1,2, _
2,0,1,1,1,0,0,0,1,2, _
2,0,1,1,1,0,0,0,1,2, _
2,1,0,0,0,1,1,1,0,2, _
2,1,0,0,0,1,1,1,0,2, _
2,1,0,0,0,1,1,1,0,2, _
2,1,1,1,1,0,0,0,0,2, _
2,2,2,2,2,2,2,2,2,2 _
]

Local $oVector = ObjCreate("WIA.Vector.1")

If Not IsObj($oVector) Then
    ConsoleWrite("+++ Error " & @error & " durning create a Vector.object." & @CRLF)
    Exit
EndIf

Local $iRed = 0xFF0000 ; RGB color
Local $iWhite = 0xFFFFFF
Local $iBlack = 0xF0F0F0

; scale image from 10x10px to 400x400px
Local $fScaleX = 40, $fScaleY = 40, $iUboundX = 10, $iUboundY = 10

ConsoleWrite("Creating array for vector..." & @CRLF)

Local $aVector_scaled = ScaleVectorArray1D($a10x10, $iUboundY, $iUboundX, $fScaleX, $fScaleY)

ConsoleWrite("Array has done." & @CRLF)

ConsoleWrite("Creating a vector image..." & @CRLF)

; adding pixels to vector
For $i = 0 To UBound($aVector_scaled) - 1
    Local $iPixel = $aVector_scaled[$i]
    Local $iColor = $iPixel = 0 ? $iWhite : $iPixel = 1 ? $iRed : $iBlack
    $oVector.Add($iColor)
Next

ConsoleWrite("Image has done." & @CRLF)

; create a img
Local $oImg = $oVector.ImageFile($fScaleX * $iUboundX, $fScaleY * $iUboundY)

; path to file
Local $sPath = @ScriptDir & "\Vector.bmp"

; delete previous file if exits.
FileDelete($sPath)

; save img to script direction.
$oImg.SaveFile($sPath)

; show result.
ShellExecute("Vector.bmp")

Func ScaleVectorArray1D($aVector1D, $iUboundY, $iUboundX, $iScaleX = 20, $iScaleY = 20)
    Local $aVector2D[$iUboundY][$iUboundX]
    Local $c = 0, $x, $y
    For $y = 0 To UBound($aVector2D) - 1
        For $x = 0 To UBound($aVector2D, 2) - 1
            $aVector2D[$y][$x] = $aVector1D[$c]
            $c += 1
        Next
    Next
    Local $iUB2x = UBound($aVector2D, 2) * $iScaleX, $iUB2y = UBound($aVector2D) * $iScaleY
    Local $aVector1D_new[$iUB2x * $iUB2y], $dx = UBound($aVector2D, 2) / $iUB2x, $dy = UBound($aVector2D) / $iUB2y
    $c = 0
    For $y = 0 To $iUB2y - 1
        For $x = 0 To $iUB2x - 1
            $aVector1D_new[$c] = $aVector2D[$y * $dy][$x * $dx]
            $c += 1
        Next
    Next
    Return $aVector1D_new
EndFunc ;==>ScaleVectorArray1D by UEZ

 

Edited by Ascer
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...