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 Edge Finder
08-14-2017, 08:05 AM
Post: #1
 (Print Post)
Rainbow Image Edge Finder
Hi Everyone! Smile
Here's a simple image edge finder program which I coded a few months ago.
There is a function called EdgeDetect() which find the edges of the image and returns a image handle with edge marked on it.

Some of the screenshots are -
[Image: 5397ba.png]

[Image: f8698e.png]

I hope you all will enjoy it!

Ashish.


Attached File(s)
.zip  ImageEdgeDetect.zip (Size: 122.54 KB / Downloads: 4)
Find all posts by this user
Like Post
08-14-2017, 09:34 AM
Post: #2
 (Print Post)
RE: Image Edge Finder
Nicely done....

J

May your journey be free of incident.

Live long and prosper.
Find all posts by this user
Like Post
08-14-2017, 09:53 AM
Post: #3
 (Print Post)
RE: Image Edge Finder
Quote:
Nicely done....
Thank you.
Find all posts by this user
Like Post
08-14-2017, 12:24 PM
Post: #4
 (Print Post)
RE: Image Edge Finder
Hi,

Oh this looks very interesting, got to try it out!

Thanks

B += _
Find all posts by this user
Like Post
08-15-2017, 12:40 AM
Post: #5
 (Print Post)
RE: Image Edge Finder
Quote:
Hi,

Oh this looks very interesting, got to try it out!
Hi bplus! Smile
Thank you!
Find all posts by this user
Like Post
08-15-2017, 11:32 AM (This post was last modified: 08-15-2017 12:22 PM by Waltersmind.)
Post: #6
 (Print Post)
RE: Image Edge Finder
Ashish,

I cleaned up, modified, and optimized your code a bit.

Since your demo was only dealing with two images, the original and the modified, I created two static images to store them in. I changed your FUNCTION to a SUB and added another parameter to it so it can access both images. Then I removed all the image creation and deletion code since it wasn't need anymore. I removed the second FOR...LOOP block since it was a near duplicate of the first block and did exactly the same thing. I also made a few more changes, but you can see that in the following code.

Here is the modified code:

Code Snippet: [Select]
DIM OriginalImage AS LONG
DIM ModifiedImage AS LONG

SCREEN _NEWIMAGE(800, 500, 32)
_TITLE "Image Edge Detect"
_SCREENMOVE 0, 0

OriginalImage = _LOADIMAGE("edge-example.jpg")
ModifiedImage = _COPYIMAGE(OriginalImage)

_PUTIMAGE (0, 0), OriginalImage

LOCATE 15, 50: PRINT "This is the original image"
LOCATE 16, 50: PRINT "Press any key to set the current tolerance."
_DISPLAY

a$ = INPUT$(1)
Tolerance! = 150
OldTolerance! = Tolerance!
ColorMode = 0

EdgeDetect OriginalImage, ModifiedImage, Tolerance!, colorAllow

DO
    _LIMIT 60
    CLS

    k$ = INKEY$

    IF k$ = "+" THEN Tolerance! = Tolerance! + 1 '20

    IF k$ = "-" AND Tolerance! >= 0 THEN Tolerance! = Tolerance! - 1 '20

    IF k$ = " " THEN
        IF ColorMode THEN ColorMode = 0 ELSE ColorMode = -1
        EdgeDetect OriginalImage, ModifiedImage, Tolerance!, ColorMode
    END IF

    LOCATE 1, 50: PRINT "Tolerance : "; Tolerance!
    LOCATE 2, 50: PRINT "IMAGE OUTPUT: ";
    IF ColorMode THEN PRINT "Color" ELSE PRINT "Monochrome"

    LOCATE 3, 50: PRINT "<+> and <-> Increases and decreases tolerance."
    LOCATE 4, 50: PRINT "<SPACE> toggles color and monochrome mode."

    IF OldTolerance! <> Tolerance! THEN
        OldTolerance! = Tolerance!
        EdgeDetect OriginalImage, ModifiedImage, Tolerance!, ColorMode
    END IF

    _PUTIMAGE (0, 0), ModifiedImage
    _DISPLAY

LOOP UNTIL k$ = CHR$(27)

CLS
PRINT "Thanks for running my program. If you find this code useful then"
PRINT "you can comment at www.qb64.net/forum"


' 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


EDIT: I just updated the code (8/15/17).

The demo now runs smoother and faster. Let me know what you think.

Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
08-15-2017, 11:42 AM (This post was last modified: 08-15-2017 11:42 AM by KingAshish.)
Post: #7
 (Print Post)
RE: Image Edge Finder
Hi Waltersmind! Smile
I like the modification done by you in the code.
It has now become perfect! Big Grin
Find all posts by this user
Like Post
08-15-2017, 12:17 PM
Post: #8
 (Print Post)
RE: Image Edge Finder
Ashish,

I just updated the code.

I made those changes to your demo so you can learn some new tricks in coding. I am a firm believer in optimization and clean code, as well as presentation. I spend more time optimizing and getting the presentation (how the user sees it when they run the application) then I do coding. That is why it takes me longer to create projects than other people.

On a side note, I personally do not like using a ton of IF...THEN statements, so I try to think of the logic in a different perspective. The many IF...THEN statements you used in your original code were slowing the rendering down. It wasn't the IF...THEN statements themselves that were slowing things down, but the PSET(x,y),colr& that you used at the end of each. This was causing the app to draw the same pixel many times instead of just once.

Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
The following 1 user Likes Waltersmind's post:
KingAshish



Forum Jump:


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




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