Convert region in current image
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Convert region in current image
Hello World of IM!
I have a question about convert some region in current image.
Currently i used distort but i'm not shure that i put the points correctly in the image.
i want convert image to result something like in example
http://joxi.ru/YmEVazpIyJD626
now i try this command line but something wrong
exec("convert files/4.jpg -virtual-pixel Black -distort Shepards '
0,762 0,762 0,0 0,0 685,0 685,0 685,762 685,762
370,335 370,335 370,265 370,265 506,265 506,265 508,342 508,342
373,333 373,313 373,303 373,323
399,333 399,353 399,303 399,283'
files/1440514887.png");
in this example i want to move up two line in region which in fixed region
the real problem is in : some points that i`ll pedifined have to move up. But some points neer baselinae also move down .. i do not understand why?
Original image here http://joxi.ru/n2Y8ag0szZyMm6
Result image http://joxi.ru/BA0d05bsDPDlAy
where do i wrong?
I have a question about convert some region in current image.
Currently i used distort but i'm not shure that i put the points correctly in the image.
i want convert image to result something like in example
http://joxi.ru/YmEVazpIyJD626
now i try this command line but something wrong
exec("convert files/4.jpg -virtual-pixel Black -distort Shepards '
0,762 0,762 0,0 0,0 685,0 685,0 685,762 685,762
370,335 370,335 370,265 370,265 506,265 506,265 508,342 508,342
373,333 373,313 373,303 373,323
399,333 399,353 399,303 399,283'
files/1440514887.png");
in this example i want to move up two line in region which in fixed region
the real problem is in : some points that i`ll pedifined have to move up. But some points neer baselinae also move down .. i do not understand why?
Original image here http://joxi.ru/n2Y8ag0szZyMm6
Result image http://joxi.ru/BA0d05bsDPDlAy
where do i wrong?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert region in current image
Shepards distort uses every pixel in the image and weights them according the the inverse squared distance to the control points. I do not think that is a good way to change the image locally.
What is your platform and version of Imagemagick?
If on Linux, Mac OSX or Windows w/Cygwin, you might look at my script, meshwarp, at the link below.
What is your platform and version of Imagemagick?
If on Linux, Mac OSX or Windows w/Cygwin, you might look at my script, meshwarp, at the link below.
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Re: Convert region in current image
My platform is Linux. Version: ImageMagick 6.5.4-7 2012-05-07 Q16 OpenMP
You talk about this script? http://www.fmwconcepts.com/imagemagick/ ... /index.php
How to use this script from PHP script ?
i try to setup all as in manual but have an error:
[root@localhost files]# bash /var/www/html/lift3/files/meshwarp -f my.txt -i -p guinea-pig-5.jpg 5555.png
num records=126
num scr pts=44
num dst pts=44
num triangles=81
Processing Triangle:
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
0
convert: invalid argument for option `-roll': ++ @ convert.c/ConvertImageCommand/2192.
[root@localhost files]#
You talk about this script? http://www.fmwconcepts.com/imagemagick/ ... /index.php
How to use this script from PHP script ?
i try to setup all as in manual but have an error:
[root@localhost files]# bash /var/www/html/lift3/files/meshwarp -f my.txt -i -p guinea-pig-5.jpg 5555.png
num records=126
num scr pts=44
num dst pts=44
num triangles=81
Processing Triangle:
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
convert: missing expression `' @ fx.c/FxEvaluateSubexpression/2733.
0
convert: invalid argument for option `-roll': ++ @ convert.c/ConvertImageCommand/2192.
[root@localhost files]#
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Re: Convert region in current image
installed and run your script on Mac Os Yosemite successed!
http://joxi.ru/Vm6yxZ3Cpz1qrZ
Where is the source pionts end destination points?
Can you explain, please?
http://joxi.ru/Vm6yxZ3Cpz1qrZ
Where is the source pionts end destination points?
Can you explain, please?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert region in current image
I am not sure what you are asking?leos2009 wrote: Where is the source pionts end destination points?
Can you explain, please?
The points and triangles were selected manually. They are shown in one of the images at http://www.fmwconcepts.com/imagemagick/ ... /index.php.
They are described in the Description section.
The list contains first the src and dst x,y control points, one pair per line. After that it contains the triangle vertex indices, one triangle per line. The indices are the line numbers of the control point pairs in the list.
If that is not what you are asking, please explain further.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert region in current image
A few weeks back, I also started writing a script to do something like what I think you want by using -compose displace and -motion-blur. Right now it only works for vertical displacements. To finish the script, I need to make it work for arbitrary directions. I have a start on that. For the examples below, you specify a position (the center of his left eye on the right side of the image), vertical distance for the motion-blur, radius of the effect and amount of softening of the motion-blur. Here are two examples:
Input:
Push Up Example:
Pull Up Example:
Two other variations can be created by simply changing the sign of -90 to +90 in the motion-blur.
Input:
Push Up Example:
Code: Select all
xpos=225
ypos=212
dist=40
radius=30
soften=30
ypos=$(($ypos - $dist))
convert Bill_Murray_small.jpg \
\( -clone 0 -fill "gray(50%)" -colorize 100% \) \
\( -clone 0 -fill black -colorize 100% \) \
\( -clone 2 -fill white -draw "translate $xpos,$ypos circle 0,0 0,$radius" -alpha off \
-motion-blur 0x${dist}-90 -blur 0x$soften \
-clone 1 +swap -compose plus -composite \) \
-delete 2 -compose over -define compose:args=-${dist}x${dist} \
-compose displace -composite Bill_Murray_small_localwarp13a.jpg
Pull Up Example:
Code: Select all
xpos=225
ypos=212
dist=40
radius=30
soften=30
ypos=$(($ypos + $dist))
convert Bill_Murray_small.jpg \
\( -clone 0 -fill "gray(50%)" -colorize 100% \) \
\( -clone 0 -fill black -colorize 100% \) \
\( -clone 2 -fill white -draw "translate $xpos,$ypos circle 0,0 0,$radius" -alpha off \
-motion-blur 0x${dist}-90 -blur 0x$soften \
-clone 1 +swap -compose plus -composite \) \
-delete 2 -compose over -define compose:args=-${dist}x${dist} \
-compose displace -composite Bill_Murray_small_localwarp13b.jpg
Two other variations can be created by simply changing the sign of -90 to +90 in the motion-blur.
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Re: Convert region in current image
Thank you so much! Your scripts helped me greatly! I really admire what you do!
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Re: Convert region in current image
i created custom example video in Youtube what i wanted https://youtu.be/HKf_zLj_zts Thank you!
used: jquery, php, imagemagick
used: jquery, php, imagemagick
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert region in current image
Very nice. Can you tell us how you used Imagemagick to do that?
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Re: Convert region in current image
when we change seek bar value html page sends Ajax request for a php file.
HTML
UPLOAD.PHP
php uses exec() command and returns converted file
html5(canvas element) draw returned file in current html page
And i used semi ellipse in your algoritm
-draw "translate '.$xpoz.','.$ypoz.' rotate -180 ellipse 0,0 '.$radius.',10 0,180" but not circle
HTML
Code: Select all
<!-- xxpoz,yypoz,rradius,ssoften,ddist - are hidden input values in html page-->
<script>
function uploads(xxpoz,yypoz,rradius,ssoften,ddist) {
$.post( "upload.php", {
xpoz: xxpoz,
ypoz: yypoz,
radius: rradius,
soften: ssoften,
dist:ddist,
beforeSend: function(){$("#splash").html('<img src="loading.gif">Processing...');}
},
onAjaxSuccess
);
}
function onAjaxSuccess(data){
var file = data.split('#%#');
var myfile = file[2];
var width = 290;
var height = 365;
function loadImage(srcs) {
imgs = new Image();
imgs.onload = function() {
var canvas = document.getElementById('canvas2');
canvas.width = width;
canvas.height = height;
canv = canvas.getContext('2d');
canv.drawImage(imgs, 0, 0, canvas.width, canvas.height);
}
imgs.src = srcs;
}
loadImage('files/'+myfile);
document.getElementById('splash').innerHTML = 'Successed...';
}
</script>
Code: Select all
<?php
$xpoz = $_POST['xpoz'];
$ypoz = $_POST['ypoz'];
$radius = $_POST['radius'];
$soften = $_POST['soften'];
$dist = $_POST['dist'];
$filename = time();
$path_file = 'files/'.$filename.'.png';
$convert = '/opt/local/bin/convert'; // IM for MAC OS
$myfile = 'files/Bill_Murray_small.jpg';
$converted = 'files/converted.png';
//LEFT EYE
exec($convert.' '.$myfile.' -resize 290 '.$converted.' && '.$convert.' '.$converted.' \
\( -clone 0 -fill "gray(50%)" -colorize 100% \) \
\( -clone 0 -fill black -colorize 100% \) \
\( -clone 2 -fill white -draw "translate '.$xpoz.','.$ypoz.' rotate -180 ellipse 0,0 '.$radius.',10 0,180" -alpha off \
-motion-blur 0x'.$dist.'-90 -blur 0x'.$soften.' \
-clone 1 +swap -compose plus -composite \) \
-delete 2 -compose over -define compose:args=-'.$dist.'x'.$dist.' \
-compose displace -composite files/finish_left.jpg');
////.........
//RIGHT EYE = $xpoz - 80
////.........
echo 'true#%#'.$somevar.'#%#'.$filename;
?>
html5(canvas element) draw returned file in current html page
And i used semi ellipse in your algoritm
-draw "translate '.$xpoz.','.$ypoz.' rotate -180 ellipse 0,0 '.$radius.',10 0,180" but not circle
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert region in current image
Semi-ellipse -- very clever! Thanks for posting what you did.
- leos2009
- Posts: 15
- Joined: 2015-08-25T07:50:55-07:00
- Authentication code: 1151
- Location: Ukraine, Kiev
- Contact:
Re: Convert region in current image
i have an error in this algoritm. Help please!
location points to move in right eye
convert: unable to open image ` (': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to parse expression `)' @ error/convert.c/ConvertImageCommand/601.
Can I use path instead ellipse ?
orig file
what's wrong in this command?
location points to move in right eye
Code: Select all
root$/opt/local/bin/convert files/triangles3.png \
\( -clone 0 -fill "gray(50%)" -colorize 100% \) \
\( -clone 0 -fill black -colorize 100% \) \
\( -clone 2 -fill white -draw "translate 180,123 path 'M 127,163 L 122,201 L 100,201 Z'" -alpha off \
-motion-blur 0x0-90 -blur 0x35 \ -clone 1 +swap -compose plus -composite \) \
-delete 2 -compose over -define compose:args=-0x0 \
-compose displace -composite files/1441637419.png
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to parse expression `)' @ error/convert.c/ConvertImageCommand/601.
Can I use path instead ellipse ?
orig file
what's wrong in this command?
Last edited by leos2009 on 2015-09-07T08:09:13-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert region in current image
Your command runs without complaint for me. (Cygwin bash, IM v6.9.1-6.)
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert region in current image
On that screenshot, the command is not divided into lines, so there are scattered backslahes \ within the command. Bash will pass the two characters " (" to IM instead of the single character "(". The error message says this is happening.
snibgo's IM pages: im.snibgo.com