Discussions related to Visual Prolog
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

How to get binary data from a picture

Unread post by Paul Cerkez »

In the old VIP 6.x (and earlier) there were the VPI:pict* predicates for doing binary manipulation of BMP images (among other things). So far in VIP 10ce, I don't see anything similar.
When I did a search in the VPI Wiki, it referred a lot of references to VIP7.x
However, on one in the Wiki pages there is mention of a GUI class and it mentions being built on the VPI package. I do remember having to specifically declare (open) the vpidomains.

My question is simple (I hope), can I still pull in a BMP and strip out the binary?

Here is my code from 10+ years ago.

Code: Select all

class predicates   pull_binary : (string).     clauses    pull_binary(Filename):-         retractall(tempIn(_)),         try                  PictIn = vpi::pictLoad(Filename),                  pictBin := vpi::pictToBin(PictIn)          catch TraceId do                  exceptionDump::dumpToStdOutput (TraceId)          end try,         TotalByteCount_Raw = binary::getSize(pictBin),         DELTA = TotalByteCount_Raw mod 3,         if 0= DELTA then             TotalByteCount = TotalByteCount_Raw         else             TotalByteCount = TotalByteCount_Raw - DELTA         end if,                               Pad1 = binary::createAtomic(1),         Pad2 = binary::createAtomic(2),                 % get the offset         B_out = binary::getBinaryAtomic(pictBin, 2,2),           % pad it out to 4 bytes for conversion         B_outPadded2 = binary::concatAtomic( B_out, Pad2),                 % gets the offset         binary::getValue(B_outPadded2,0, integer(V)),           foreach S = std::fromToInStep(V, TotalByteCount-V, 3) do             % get the 2 bytes for color and pad             First = binary::getBinaryAtomic(pictBin,S,3),             B_outPadded1 = binary::concatAtomic( First, Pad1),                       % convert bin to int             binary::getValue(B_outPadded1,0, integer(V1)),             output := convert(positive,V1),             assertz(tempIn(output))                     end foreach,         if _X = string::search(Filename, "Neg",string::caseInsensitive() ) then             console::write("Neg found \n"),                 globals::desired_Output := 0.0         else             console::write("Neg NOT  found \n"),                 globals::desired_Output := 1.0         end if/*,
I don't show it here, but I would make decisions based on the extracted binary RGB values and sometimes change them before running the whole image through a NN.
AI Rules!
P.
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Re: How to get binary data from a picture

Unread post by Martin Meyer »

Hi Paul,

all predicates of your old code are still there in VIP 10ce.

I have tried it, created a new console project in VIP 10ce and put the code with a little add-on in main.pro:

Code: Select all

class globals   properties     desired_Output : real.   end class globals   implement globals   class facts     desired_Output : real := erroneous.   end implement globals   %---   implement main     open core   class facts     tempIn : (positive) nondeterm.     pictBin : binary := erroneous.     output : positive := erroneous.   class predicates     pull_binary : (string). clauses     pull_binary(Filename) :-         retractall(tempIn(_)),         try             PictIn = vpi::pictLoad(Filename),             pictBin := vpi::pictToBin(PictIn)         catch TraceId do             exceptionDump::dumpToStdOutput(TraceId)         end try,         TotalByteCount_Raw = binary::getSize(pictBin),         DELTA = TotalByteCount_Raw mod 3,         if 0 = DELTA then             TotalByteCount = TotalByteCount_Raw         else             TotalByteCount = TotalByteCount_Raw - DELTA         end if,         Pad1 = binary::createAtomic(1),         Pad2 = binary::createAtomic(2),         % get the offset         B_out = binary::getBinaryAtomic(pictBin, 2, 2),         % pad it out to 4 bytes for conversion         B_outPadded2 = binary::concatAtomic(B_out, Pad2),         % gets the offset         binary::getValue(B_outPadded2, 0, integer(V)),         foreach S = std::fromToInStep(V, TotalByteCount - V, 3) do             % get the 2 bytes for color and pad             First = binary::getBinaryAtomic(pictBin, S, 3),             B_outPadded1 = binary::concatAtomic(First, Pad1),             % convert bin to int             binary::getValue(B_outPadded1, 0, integer(V1)),             output := convert(positive, V1),             assertz(tempIn(output))         end foreach,         if _X = string::search(Filename, "Neg", string::caseInsensitive()) then             console::write("Neg found \n"),             globals::desired_Output := 0.0         else             console::write("Neg NOT  found \n"),             globals::desired_Output := 1.0         end if.   clauses     run() :-         Filename = @"C:\Program Files (x86)\Visual Prolog\10\appData\ProjectTemplates\GUI\MDI\taskWindow\Toolbars\SaveFileBitmap.bmp", %put a pic file name here         pull_binary(Filename).   end implement main   goal     console::runUtf8(main::run).
At least that compiles and runs.
Regards Martin
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

Re: How to get binary data from a picture

Unread post by Paul Cerkez »

Awesome, great news, Thanks Martin.
It will save me a lot of work if I can re-use some of my old code. :-)
AI Rules!
P.
Post Reply