Resize an image to the white area of ​​the mask

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ovazquez
Posts: 3
Joined: 2017-05-27T17:43:20-07:00
Authentication code: 1151

Resize an image to the white area of ​​the mask

Post by ovazquez »

Hello
I have the following problem: I have an furniture image to which it applies a texture on a piece of furniture using a mask, the dimensions of the two images and the mask are the same. But I want that the texture image to be resized and fit the white area of ​​the mask, how could I do this?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Resize an image to the white area of ​​the mask

Post by GeeMack »

ovazquez wrote: 2017-05-27T18:06:00-07:00I have the following problem: I have an furniture image to which it applies a texture on a piece of furniture using a mask, the dimensions of the two images and the mask are the same. But I want that the texture image to be resized and fit the white area of ​​the mask, how could I do this?
That sounds like a pretty simple task for ImageMagick, but the specifics might be different from one version to another or on some particular operating system or platform. Please check the suggestions for posting questions on THIS page, then let us know what sort of system you're running on, what version of IM you're using, and provide a couple sample images of what you're trying to do. It's likely you'll get some pretty good solutions here.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize an image to the white area of ​​the mask

Post by fmw42 »

I am really unclear about what you want to do. You say you already have a texture image and mask image that match. Why do you need to resize the texture image? If the white area of the mask does not fit, is it really just a resize and not a warp/distortion. If a simple resize, then you likely need to measure at least 3 corresponding points on the texture image and the mask white are and use -distort Affine.

See http://www.imagemagick.org/Usage/distorts/#affine

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
ovazquez
Posts: 3
Joined: 2017-05-27T17:43:20-07:00
Authentication code: 1151

Re: Resize an image to the white area of ​​the mask

Post by ovazquez »

Well, sorry for my bad english and short description.
Im using:
- windows 8.1 SO
- ImageMagick 6.9.8 Q8
- PHP API, module imagick v3.4.3
- Wamp server 3.0.6 running in local

Php script:
$dir = __DIR__;
$mueble = new Imagick($dir . "/mueble.jpg");
$texture1 = new Imagick($dir . "/texture6.jpg");
$mask = new Imagick($dir . "/a_mask.png");
$mask->negateimage(true);
$mueble->setimageclipmask($mask);
$mueble->compositeimage($texture1, Imagick::COMPOSITE_OVERLAY, 0, 0);
$mueble->writeImage($dir . "/mueble1.jpg");

I want that texture6.jpg to be resized and adapted to the size of the white area in the mask a_mask.png to achieve a better visual appearance

mueble.jpg
Image

texture6.jpg
Image

a_mask.png
Image

Result -> mueble1.jpg
Image

Expected result -> mueble2.jpg (sorry bad photoshop)
Image

Please, you could help me. I'm new using ImageMagick and I've tried to find a solution but I can not. Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize an image to the white area of ​​the mask

Post by fmw42 »

None of your images show up. Perhaps you have them in a private account that needs a username and password? Please try again.
ovazquez
Posts: 3
Joined: 2017-05-27T17:43:20-07:00
Authentication code: 1151

Re: Resize an image to the white area of ​​the mask

Post by ovazquez »

Sorry, make right click over image and select Open in new tab
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize an image to the white area of ​​the mask

Post by fmw42 »

You are using dropbox. But you have not set the images to be shareable. I can see them, but cannot download them. Please fix and edit your links if necessary. Or try posting to some other free hosting service that does not make you sign in to access them.

From what I see, you need to draw a mask for each surface of the sofa. Then you need to perspectively transform the texture to a similar perspective, then compose than perspective texture onto the sofa using the mask to limit it. I know of no image processing tool that does that automatically. However, there are probably 3D modeling and texture mapping tools that might.

If your texture image is not big enough for the given surface in the sofa image, then you can try to tile it out to make it larger so that it fills the full mask area. You need to tile it out until it is big enough to cover the mask are at the scale and perspective you want.

See http://www.imagemagick.org/Usage/canvas/#tile and my unix bash shell script, tiler, at my link below.
Post Reply