I would like to depth-merge a few images similar to GIMP depth merge operation:
http://docs.gimp.org/en/plug-in-depth-merge.html
I looked at the composite command, but have not found anything like it.
Is it possible?
Thanks!
GIMP-like Depth Merge
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: GIMP-like Depth Merge
you can do that I believe with a (binary or 8-bit) mask image and either some colorimage or another image. there are lots of ways to approach it, but it depends upon exactly what two images you want to merge and what effect you want. One way is:
convert image1 image 2 maskimage -compose over -composite result
see
http://www.imagemagick.org/Usage/masking/#masks
http://www.imagemagick.org/Usage/layers/
convert image1 image 2 maskimage -compose over -composite result
see
http://www.imagemagick.org/Usage/masking/#masks
http://www.imagemagick.org/Usage/layers/
Re: GIMP-like Depth Merge
Thanks for the reply.
let me explain more:
I have a 3d model that is made of several objects. I have also several images that are snapshots of the 3d model at a certain camera position. For each image, a different set of objects in the 3d model are shown and the screenshot image taken. Also for each image, a depth map is generated. The values of a depth map is the distance from the camera to the object. This data came from the opengl frame buffer GL_DEPTH_COMPONENT.
I want to combine the images using the depth data, in essence creating the screenshot if all the models are loaded in 3D. The depth data has to be used to 'sort' the pixels.
From the doc, the compose command only takes one maskimage, where i need to combine two (or more) images, each image has its own depth mask.
Is there a way to do this?
let me explain more:
I have a 3d model that is made of several objects. I have also several images that are snapshots of the 3d model at a certain camera position. For each image, a different set of objects in the 3d model are shown and the screenshot image taken. Also for each image, a depth map is generated. The values of a depth map is the distance from the camera to the object. This data came from the opengl frame buffer GL_DEPTH_COMPONENT.
I want to combine the images using the depth data, in essence creating the screenshot if all the models are loaded in 3D. The depth data has to be used to 'sort' the pixels.
From the doc, the compose command only takes one maskimage, where i need to combine two (or more) images, each image has its own depth mask.
Is there a way to do this?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: GIMP-like Depth Merge
perhaps it is best if you could provide a link to a set of image as I don't know how a depth map as mask image would work. but nevertheless, you can chain the composite command
convert image1 image2 maskimage1 -compose over -composite \
image 3 maskimage2 -compose over -composite \
image 4 maskimage3 -compose over -composite \
... etc ... \
resultimage
convert image1 image2 maskimage1 -compose over -composite \
image 3 maskimage2 -compose over -composite \
image 4 maskimage3 -compose over -composite \
... etc ... \
resultimage
Re: GIMP-like Depth Merge
Please see the first example for:
http://docs.gimp.org/en/plug-in-depth-merge.html
Each image has a depth map. To do this manually, for each pixel, take the depth map values from each map, sort it, and output the pixel color based on the highest depth map value. Repeat for all pixels.
What I'm looking for is very similar to http://www.imagemagick.org/Usage/layers/#composite, but only the sort order of each pixel is determined by the depth map.
http://docs.gimp.org/en/plug-in-depth-merge.html
Each image has a depth map. To do this manually, for each pixel, take the depth map values from each map, sort it, and output the pixel color based on the highest depth map value. Repeat for all pixels.
What I'm looking for is very similar to http://www.imagemagick.org/Usage/layers/#composite, but only the sort order of each pixel is determined by the depth map.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: GIMP-like Depth Merge
I have taken the first example from your reference. Note that map1 and map2 are the inverted or negated versions of each other. So for two image blending, you only need one or the other. I have processed the map1 a little to make it more compatible with IM.
Process the map1 image for two examples:
convert depthmerge-source-map1.png -auto-level -threshold 50% depthmerge-source-map1a.png
convert depthmerge-source-map1a.png -blur 20x65000 depthmerge-source-map1b.png
Do composites:
convert depthmerge-source-image1.png depthmerge-source-image2.png depthmerge-source-map1a.png -compose over -composite depthmerge_12a.png
convert depthmerge-source-image1.png depthmerge-source-image2.png depthmerge-source-map1b.png -compose over -composite depthmerge_12b.png
Process the map1 image for two examples:
convert depthmerge-source-map1.png -auto-level -threshold 50% depthmerge-source-map1a.png
convert depthmerge-source-map1a.png -blur 20x65000 depthmerge-source-map1b.png
Do composites:
convert depthmerge-source-image1.png depthmerge-source-image2.png depthmerge-source-map1a.png -compose over -composite depthmerge_12a.png
convert depthmerge-source-image1.png depthmerge-source-image2.png depthmerge-source-map1b.png -compose over -composite depthmerge_12b.png
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: GIMP-like Depth Merge
This takes me back to my Graduate Computer Science days! Depth ordering objects!
But I have a lot more skills, and techniques up my sleeves since then!
There is a mode that may be of use on a per pixel bases. LightenIntensity.
http://www.imagemagick.org/Usage/compos ... nIntensity
If the input is the depth map of the two images you can use this compose to generate a mask of which object is 'closer' based on those two depth maps. The alpha map can be anything, but specifically it can be the 'object' index, so at the end the alpha channel contains the index of the closer object.
That gives you which object is 'in front' at every pixel location. for the two objects. But object edges tend to be semi-transparent, so you can not just pick a pixel from the appropriate object image.
What you need is instead to pick pixels from two images. One with the object composed over the other, and visa-versa. That way you get the right color 'blending' along the edges. It is from these two images that you would use the mask to 'pixel pick' the right color.
This method even allows you to even have two objects the overlap each other, such as a torus that has a cylinder though the middle. some parts will have the torus in frount, in others the cylinder will be in front.
It will even handle objects that pass through each other, BUT will not provid proper anti-aliasing of the pixels at that join, Not without a lot more work!
If you have an example of two objects (with anti-aliased edges), preferably overlapping just as I suggested. I can try to work out the exact commands needed.
The Gimp example it rather useless and not very clear. Some small, scaled down examples from your openGL environment will be much more useful!
But I have a lot more skills, and techniques up my sleeves since then!
There is a mode that may be of use on a per pixel bases. LightenIntensity.
http://www.imagemagick.org/Usage/compos ... nIntensity
If the input is the depth map of the two images you can use this compose to generate a mask of which object is 'closer' based on those two depth maps. The alpha map can be anything, but specifically it can be the 'object' index, so at the end the alpha channel contains the index of the closer object.
That gives you which object is 'in front' at every pixel location. for the two objects. But object edges tend to be semi-transparent, so you can not just pick a pixel from the appropriate object image.
What you need is instead to pick pixels from two images. One with the object composed over the other, and visa-versa. That way you get the right color 'blending' along the edges. It is from these two images that you would use the mask to 'pixel pick' the right color.
This method even allows you to even have two objects the overlap each other, such as a torus that has a cylinder though the middle. some parts will have the torus in frount, in others the cylinder will be in front.
It will even handle objects that pass through each other, BUT will not provid proper anti-aliasing of the pixels at that join, Not without a lot more work!
If you have an example of two objects (with anti-aliased edges), preferably overlapping just as I suggested. I can try to work out the exact commands needed.
The Gimp example it rather useless and not very clear. Some small, scaled down examples from your openGL environment will be much more useful!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/