Page 1 of 2
Convert region in current image
Posted: 2015-08-25T08:13:22-07:00
by leos2009
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?
Re: Convert region in current image
Posted: 2015-08-25T09:27:24-07:00
by fmw42
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.
Re: Convert region in current image
Posted: 2015-08-26T01:35:13-07:00
by leos2009
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]#
Re: Convert region in current image
Posted: 2015-08-26T07:35:35-07:00
by leos2009
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?
Re: Convert region in current image
Posted: 2015-08-26T09:24:16-07:00
by fmw42
leos2009 wrote:
Where is the source pionts end destination points?
Can you explain, please?
I am not sure what you are asking?
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.
Re: Convert region in current image
Posted: 2015-08-26T19:29:42-07:00
by fmw42
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:
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.
Re: Convert region in current image
Posted: 2015-08-27T05:26:41-07:00
by leos2009
Thank you so much! Your scripts helped me greatly! I really admire what you do!
Re: Convert region in current image
Posted: 2015-08-28T06:43:58-07:00
by leos2009
i created custom example video in Youtube what i wanted
https://youtu.be/HKf_zLj_zts Thank you!
used: jquery, php, imagemagick
Re: Convert region in current image
Posted: 2015-08-28T09:39:24-07:00
by fmw42
Very nice. Can you tell us how you used Imagemagick to do that?
Re: Convert region in current image
Posted: 2015-08-30T07:34:21-07:00
by leos2009
when we change seek bar value html page sends Ajax request for a php file.
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>
UPLOAD.PHP
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;
?>
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
Re: Convert region in current image
Posted: 2015-08-30T11:07:18-07:00
by fmw42
Semi-ellipse -- very clever! Thanks for posting what you did.
Re: Convert region in current image
Posted: 2015-09-07T07:35:32-07:00
by leos2009
i have an error in this algoritm. Help please!
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: 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?
Re: Convert region in current image
Posted: 2015-09-07T07:51:13-07:00
by snibgo
Your command runs without complaint for me. (Cygwin bash, IM v6.9.1-6.)
Re: Convert region in current image
Posted: 2015-09-07T07:59:38-07:00
by leos2009
screen
Re: Convert region in current image
Posted: 2015-09-07T08:28:22-07:00
by snibgo
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.