Image manipulation
Posted
#1
(In Topic #160)
Trainee
Thanks.
Posted
Guru

Have you got a couple of pictures you can show us as an example of what you are trying to do? What type of file compression are you using as I think this would not be possible with .jpg files?
Posted
Regular

RichardB said
…I'm trying to write a piece of code to perform some image manipulation - specifically, to mathematically subtract one image from another…
I can't see a ready made function for this in Gambas. So you would either have to cycle through the 2 dimensional array for each of the 2 images, and subtract each value, or maybe call an external script to do the work (maybe using GIMP).
See also:-
https://uk.mathworks.com/help/images/ref/imsubtract.html
/comp/gb.image/image - Gambas Documentation
Posted
Regular

Create a new project, make sure component gb.Image is included.
Add 2 textboxes and 1 button. Pre-load the text boxes with the paths of 2 equal sized images (I used jpegs).
The code:-
Code (gambas)
- myImage3 = myImage1
- myImage3[indexX, indexY] = 0
- myImage3[indexX, indexY] = myImage1[indexX, indexY] - myImage2[indexX, indexY]
- myImage3.Save("/home/steve/Gambas/ImageManipulation/image3.jpg")
I couldn't remember how to create a blank image the right size (for myImage3) so I just copied myImage1 into myImage3.
I hope this helps.
Posted
Regular

The following 2 images where time-lapse photos taken with my trail-cam:
…and here is the result…
only unique pixels in image1 are reproduced in image3.
Posted
Regular

Here's a forum thread on how to do it with ImageMagick:
Simple subtract - Legacy ImageMagick Discussions Archive
Posted
Regular

Posted
Trainee
I really appreciate everyone's help, and special thanks to steve - that looks like the sort of solution I've been chasing. Unfortunately I'm at work at the moment, so I won't be able to test out your code example until I go home. I'll let you know how it turns out.
Thanks again.
-RB
1 guest and 0 members have just viewed this.






