Author Topic: Image processing library  (Read 10698 times)

0 Members and 1 Guest are viewing this topic.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Image processing library
« on: January 16, 2019, 08:56:48 am »
This is another small library of mine, which was lost with the old qb64(.net) forum. Since then the library got a complete revision, adding support for using mask images to determine the image areas to process. This is completly optional, so if you want to process the entire image, then simply specify an invalid handle (-1) for the mask parameter. Also still available is the processing area selection by min/max pixel coordinates.

EDIT:
Download attachement removed ...
This library is now part of my Libraries Collection, which you can download from the bonus stuff section here: https://qb64forum.alephc.xyz/index.php?topic=809
« Last Edit: January 31, 2022, 06:08:56 pm by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Image processing library
« Reply #1 on: January 17, 2019, 02:18:53 pm »
Thanks RhoSigma

This is a nice set of routines and the demo is not bad either specially for this time of year.

Have you ever tried converting an image to B&W ASCII characters?

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Image processing library
« Reply #2 on: January 18, 2019, 04:10:19 am »
Have you ever tried converting an image to B&W ASCII characters?

I've an idea how to do that easily, but not yet made any progress in code.

The idea is to give a string containing 2-16 chars representing the desired graylevels ascending from black(0) to white(255) (eg. " .:-=+oO80@#"), and also give the desired width of the ascii art in chars (eg. 120) as well as the desired font height (eg. 8). Now dividing the image in blocks according to the given charwidth/fontheight and then calculate the graylevel of each block by grayscaling each of its pixels and building the average of all pixels in a block, which will result in regular gray values from 0-255. According to the calculated graylevel the respective char will be chosen from the given string.
« Last Edit: January 22, 2019, 04:02:40 am by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Image processing library
« Reply #3 on: January 18, 2019, 03:53:14 pm »
Hi all,
here is a prototype of the ASCII-Art function as I did describe it in the previous post. There are certainly many things which can be improved on the function, but as I don't need those stuff, I will not further develop it. Just made it to transform my idea into some real code, but further improvement I'll leave on the SCREEN 0 maniacs. Or maybe Steve is willing to make "The Overengineered 'ASCII-Art' FUNCTION." :)

EDIT:
Codebox removed ...
This function is now available as example program for the Image processing library, which is part of my Libraries Collection. You can download the collection from the bonus stuff section here: https://qb64forum.alephc.xyz/index.php?topic=809
« Last Edit: January 31, 2022, 06:09:50 pm by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Image processing library
« Reply #4 on: January 19, 2019, 11:16:23 am »
That is excellent! Thanks  :)

Offline Donald Foster

  • Newbie
  • Posts: 63
    • View Profile
Re: Image processing library
« Reply #5 on: January 19, 2019, 04:02:37 pm »
Hello,

I downloaded it in my QB64 main folder, but could not find the ImgProcDemo.bas file. These kind of problems always happen to me when I try downloading stuff like this with multiple files. What a I doing wrong? Nobody else seems to have this problem.

Donald

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Image processing library
« Reply #6 on: January 19, 2019, 04:18:17 pm »
It will work for any image just change filename for image (use standard image formats).

I am referring to the second code snippet, which works independently of the first code set RhoSigma packed up.

ascii yosimite same.PNG
* ascii yosimite same.PNG (Filesize: 51.88 KB, Dimensions: 1128x731, Views: 349)
« Last Edit: January 19, 2019, 04:28:17 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Image processing library
« Reply #7 on: January 19, 2019, 04:31:42 pm »
Hello,

I downloaded it in my QB64 main folder, but could not find the ImgProcDemo.bas file. These kind of problems always happen to me when I try downloading stuff like this with multiple files. What a I doing wrong? Nobody else seems to have this problem.

Donald

You could not find that file after you extracted from the .7z file? Where did you extract to? It should be there.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Image processing library
« Reply #8 on: January 20, 2019, 08:31:48 am »
Hi bplus,
you may have noticed, that the routine does crop the right/bottom parts of the given image, if its pixel width is not evenly divisible by the desired charwidth. I've just updated the codebox above with a fixed routine which always give you a best fit result for every arbitrary image size and desired charwidth.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Image processing library
« Reply #9 on: January 20, 2019, 11:22:36 am »
Hi RhoSigma,

I did notice something on left edge and wondered if was fitting on right side. My first concern however is the bottom edge, that I can't see, perhaps because of title bar? the window does not fit my screen. Should be no problem working it out for my screen size, you've done all the hard work.

I am toying with idea of expanding the character set after some optimizing experiments ie the best spread of n pixels that form a character... but I suspect you already have the best set for 16 or less characters. For gray levels, you want best symmetric spread of n pixels. I am also toying with idea of trying to match the image cell with the closest character, sort of like image recognition, in order to get closer to a line drawing if possible. So far, this toying has not got me energized enough to start something. I will get going when I get excited about an actual application.