You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Image Sharpen Filter
08-17-2017, 11:17 AM
Post: #1
 (Print Post)
Image Sharpen Filter
Hi Everyone! Smile
I've created a Image Sharpen Filter and I don't know whether it is accurate or not.
But for me, it is working good.
Here's the code -
Code Snippet: [Select]
screen _newimage(600,400,32)

img& = _loadimage("eye.png")
sharpImg& = _newimage(_WIDTH(img&, _HEIGHT(img&, 32)
_putimage (0,0), img&
sleep
sharpImage img&, sharpImg&, 13,240

'proof...  for those who think that both images are looking same.
'This will porve whether there is difference between these two images or not.
_putimage (_width(img&,0), sharpImg&
for  y = 0 to _HEIGHT(img&
   for x = 0 to _width(img&
        _source img&
        pixel_col~& = point(x,y)
        _source sharpImg&
        pixel_col_2~& = point(x,y)
        if pixel_col~& <> pixel_col_2~&  then k = k + 1
    next
next
_source 0
locate 20,1
print "Difference - ";(k/((_width(img&-1)*(_height(img&-1)))*100;"%"

'sharpImage() by Ashish
'originalImage&: - Original handle of the image.
'modifiedImage&: - handle of the image which has to modified or updated.
'amount: - it controls how much lighter or darker the edge border becomes.
'size: - control the sharpness of the image.
sub sharpImage (originalImage&, modifiedImage&, amount, size)
   originalDest& = _DEST
    originalSource& = _SOURCE
    
    edgedImage& = _newimage(_width(originalImage&, _height(originalImage&, 32)
    EdgeDetect originalImage&, edgedImage&, 255-size, 0
    ' _putimage (0,0), edgedImage&
    ' sleep
    _SOURCE originalImage&
    _DEST modifiedImage&
    _PUTIMAGE (0,0), originalImage&
    
    for y = 0 to _height(originalImage& - 1
        for x = 0 to _width(originalImage& - 1
            Will_Be_Sharpe = 0
            _source edgedImage&
            if point(x,y) = _rgb(255,255,255) then Will_Be_Sharpe = 1
            _source originalImage&
            if Will_Be_Sharpe = 1 then
                col~& = point(x,y)
                r = _RED(col~&
                g = _GREEN(col~&
                b = _BLUE(col~&
                if brightness(col~& > 150 then pset (x,y),_rgb(r+amount,g+amount,b+amount)
                if brightness(col~& < 150 then pset (x,y),_rgb(r-amount,g-amount,b-amount)
            end if
            
        next
    next
    
    _dest originalDest&
    _source originalSource&
    
end sub

' Egde Detect Function By Ashish Kushwaha
' Modified by: Walter Whitman - The Joyful Programmer
SUB EdgeDetect (OriginalImage, ModifiedImage, Tolerance!, colorMode)

   DIM OriginalSrc AS LONG
   DIM OriginalDest AS LONG

   OriginalSrc = _SOURCE
   OriginalDest = _DEST

   _DEST ModifiedImage
   _SOURCE OriginalImage

   CLS

   FOR y = 0 TO _HEIGHT - 1
       FOR x = 0 TO _WIDTH - 1
           col& = POINT(x, y)
           r = _RED(col&
           g = _GREEN(col&
           b = _BLUE(col&
           IF NOT colorMode THEN col& = _RGB(255, 255, 255)
           IF ((r - preR) >= Tolerance!) OR ((g - preG) >= Tolerance!) OR ((b - preB) >= Tolerance!) OR ((r + g) - (preR + preG) >= Tolerance!) OR ((g + b) - (preG + preB) >= Tolerance!) OR ((b + r) - (preB + preR) >= Tolerance!) OR ((r + g + b) - (preR + preG + preB) >= Tolerance!) OR ((preR - r) >= Tolerance!) OR ((preG - g) >= Tolerance!) OR ((preB - b) >= Tolerance!) OR ((preR + preG) - (r + g) >= Tolerance!) OR ((preG + preB) - (r + b) >= Tolerance!) OR ((preB + preR) - (b + r) >= Tolerance!) OR ((preR + preG + preB) - (r + g + b) >= Tolerance!) THEN PSET (x, y), col&
           preR = r
           preG = g
           preB = b
       NEXT x
   NEXT y

   _DEST OriginalDest
   _SOURCE OriginalSrc

END FUNCTION


'function taken from p5js.bas

FUNCTION brightness! (col~&
   r! = _RED32(col~&
   g! = _GREEN32(col~&
   b! = _BLUE32(col~&
   ' a = _ALPHA32(col~&
   ' brightness! = ((r + g + b + a) / (255 * 4)) * 255
    brightness! = max(max(r!,g!),b!)
END FUNCTION

'Calculate minimum value between two values
FUNCTION min! (a!, b!)
   IF a! < b! THEN min! = a! ELSE min! = b!
END FUNCTION

'Calculate maximum value between two values
FUNCTION max! (a!, b!)
   IF a! > b! THEN max! = a! ELSE max! = b!
END FUNCTION


Note:- You'll need to download eye.png from the attachment.

Ashish.


Attached File(s) Image(s)
       
Find all posts by this user
Like Post
08-17-2017, 12:14 PM
Post: #2
 (Print Post)
RE: Image Sharpen Filter
Hi Ashish,

The image on right of the side-by-side images has more contrast and more detail, is this right?
The one on the far right seems in-between the two that are side-by-side. (Just going by the screen shot.)

Have you tested this code on an image you have blurred?

B += _
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Basic Dithering
QB64 Member Project - ARB Checkers
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Color Rotating Text
QB64 Member Project - Overboard
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Point Blank
QB64 Member Project - Quarto
QB64 Member Project - 9 Board
QB64 Member Project - Full Color LED Sign
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Swirl
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Line Thickness
QB64 Member Project - Qubic
QB64 Member Project - Othello
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Sabotage
QB64 Member Project - Amazon
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Splatter
QB64 Member Project - Algeria Weather
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Blokus
QB64 Member Project - Pivot version two
QB64 Member Project - Dreamy Clock
QB64 Member Project - Input
QB64 Member Project - Pivet version one
QB64 Member Project - Spiro Roses
QB64 Member Project - Touche
QB64 Member Project - Domain
QB64 Member Project - Rubix's Magic
QB64 Member Project - Bowditch curve
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Dakapo
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Color Triangles
QB64 Member Project - Score 4
QB64 Member Project - Inside Moves
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Foursight
QB64 Member Project - Connect Four
QB64 Member Project - Exit
QB64 Member Project - Rotating Background
QB64 Member Project - Isolation
QB64 Member Project - Kings Court