Page 2 of 3

Re: Blurred border using Mogrify

Posted: 2009-04-16T15:45:27-07:00
by fmw42
Your command seems to work for me without cropping on Mac OSX Tiger command line mode using IM 6.5.1-3 Q16. What version of IM are you using?

original:
zelda3.jpg
Image

convert zelda3.jpg \( +clone -blur 10x4 -fill white -colorize 30% \) \
\( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 \) \
-composite \
\( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 \) \
-compose screen -composite zelda3_test1.jpg

Image

I am not sure -gamma 0 is meaningful?

But here is a simpler way:

convert zelda3.jpg \( +clone -blur 10x4 -fill white -colorize 30% \) \
\( -clone 0 -shave 30x30 -bordercolor white -border 1x1 \) \
-delete 0 -gravity center -composite \
zelda3_test2.jpg

Image



Is this not what you wanted? Perhaps I misunderstand your problem.

By the way, it has been since OS 9 that I did any real Applescript. At that time I used a Mac version of ImageMagick (ImageMagick_AE by Leonard Rosenthol). I would be very interested in knowing how you go about interfacing Applescript with the OSX version of ImageMagick and how you issue Applescript commands to it these days.

Thanks

Fred

Re: Blurred border using Mogrify

Posted: 2009-04-16T16:39:00-07:00
by anthony
kilowatt wrote:i'm on mac os. i need the \\ because the command gets called from applescript.
In other words you have two layers of parsing. Apple Script, as well as Shell.

The PHP people also have the same problems, and probably very similar solutions.

See the API link above but go to PHP instead of Windows.

Re: Blurred border using Mogrify

Posted: 2009-04-17T00:04:59-07:00
by kilowatt
Hi Fred,

thanks so far for your help. The results you've posted are the same as mine. I think I've put my problems wrong.

My problem is, that the unblurred part of the picture get's cropped by the blurred frame. In your example it is the top of Zeldas hairs or the flowers in her hand, which are not clearly visible anymore because they got blurred.

My original image size is e.g. 1000x1000px, now I'd like to frame them in a 30px blurred border but the resulting image should then have 1060x1060px. My goal is, that the unblurred part of the resulting image contains the full original image.

Thanks
KW.

@anthony: AppleScript is not the problem, although I'm new to it. I test the commands in a shell before I bring them to AS. But I will take a look at the API...

Re: Blurred border using Mogrify

Posted: 2009-04-17T10:51:42-07:00
by fmw42
I think I need to see your picture and size details about how you want to crop it to be able to help. I cannot visualize what you need to do. Can you post an example here or email an example to me? If you need to email me, send to fmw at alink.net

Also I would appreciate any pointers that you have about using IM with Applescript under OSX, per my question above. I did a lot of Applescripting years ago under OS 8-9, but none since OSX and none with the current IM. So I would like to catch up just for educational purposes in case I want to use it in the future.

Fred

Re: Blurred border using Mogrify

Posted: 2009-04-19T00:15:44-07:00
by kilowatt
Hi Fred,

take this as my original image:

Image

Applying this command

Code: Select all

onvert image.jpg \\( +clone -blur 10x4 -fill white -colorize 30% \\) \\( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 \\) -composite \\( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 \\) -compose screen -composite image.jpg
gives:
Image

But I'd like to get something like this:

Image

I did this manually by first stretching it by 30px on each side. Then I applied my command and then copied my original image (which is smaller) into the center of it.

Do you see the difference?

I have to admit, that the result looks strange in some ways, e.g. the tree in the upper-left part of the background looks sort of broken...

My Applescript is this:

Code: Select all


on open theObjects
	repeat with theObject in theObjects
		
		set Aperture to my getAperture(POSIX path of theObject as string)
		
		set ExposureTime to my getExposureTime(POSIX path of theObject as string)
		
		set FocalLength to my getFocalLength(POSIX path of theObject as string)
		
		set ISOSpeed to my getISOSpeed(POSIX path of theObject as string)
		
		set DateOrigin to my getDateOrigin(POSIX path of theObject as string)
		
		do shell script "/opt/local/bin/convert '" & (POSIX path of theObject as string) & "' \\( +clone -blur 10x4 -fill white -colorize 30% \\) \\( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 -pointsize 25 -font /Library/Fonts/Cracked -fill black -gravity SouthEast -annotate +30+1 '" & FocalLength & "mm | " & ExposureTime & "s @ " & Aperture & " | ISO" & ISOSpeed & "' -gravity SouthWest -annotate +30+1 '" & DateOrigin & "' -gravity South -annotate +30+1 " & "'photos.kjal.de' " & " \\) -composite \\( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 \\) -compose screen -composite '" & (POSIX path of theObject as string) & "'"
		
	end repeat
end open

on theSplit(theString, theDelimiter)
	
	-- save delimiters to restore old settings
	set oldDelimiters to AppleScript's text item delimiters
	-- set delimiters to delimiter to be used
	set AppleScript's text item delimiters to theDelimiter
	-- create the array
	set theArray to every text item of theString
	-- restore the old setting
	set AppleScript's text item delimiters to oldDelimiters
	-- return the result
	return theArray
	
end theSplit

on getAperture(file)
	
	set Aperture to do shell script "/opt/local/bin/exiv2 -PEkt '" & (POSIX path of theObject as string) & "' | grep -E \"\\.ApertureValue\" | awk '{print $2}'"
	
	return Aperture
	
end getAperture

on getExposureTime(file)
	
	set ExposureTime to do shell script "/opt/local/bin/exiv2 -PEkt '" & (POSIX path of theObject as string) & "' | grep -E \"\\.ShutterSpeedValue\" | awk '{print $2}'"
	
	return ExposureTime
	
end getExposureTime

on getFocalLength(file)
	
	set FocalLength to do shell script "/opt/local/bin/exiv2 -PEkt '" & (POSIX path of theObject as string) & "' | grep -E \"\\.FocalLength\" | awk '{print $2}'"
	
	return FocalLength
	
end getFocalLength

on getISOSpeed(file)
	
	#set ISOSpeed to do shell script "exiv2 -PEkt '" & (POSIX path of theObject as string) & "' | grep -E \"\\.ISOSpeedRatings\" | awk '{print $2}'"
	
	set ISOSpeed to do shell script "/opt/local/bin/exiv2 -PEkt pr '" & (POSIX path of theObject as string) & "' | grep -E \"\\.ISOSpeedRatings\" | awk '{print $2}'"
	
	return ISOSpeed
	
end getISOSpeed

on getDateOrigin(file)
	
	set DateOrigin to do shell script "opt/local/bin/exiv2 -PEkt '" & (POSIX path of theObject as string) & "' | grep \"\\.DateTimeOriginal\" | awk '{print $2}'"
	
	set myArray to my theSplit(DateOrigin, ":")
	
	set DYear to item 1 of myArray
	
	set DMonth to item 2 of myArray
	
	set DDay to item 3 of myArray
	
	return DDay & "." & DMonth & "." & DYear
	
end getDateOrigin

I extended the convert... command to get the infos written into the image. In my previous version I used identify to extract the exifs but I noticed, that identify fails to get the ISO value of a *.tif image - is this a bug? There is no such problem using exiv2...

I saved this applescript as a .app file and it gets called as a Lightroom2 'Export Action'.

Re: Blurred border using Mogrify

Posted: 2009-04-19T14:25:36-07:00
by fmw42
My original image size is e.g. 1000x1000px, now I'd like to frame them in a 30px blurred border but the resulting image should then have 1060x1060px. My goal is, that the unblurred part of the resulting image contains the full original image.
But from your example above, you get a doubling of the outer 30 pixels from the original image. That is very strange and to me not very desirable. Is that really what you want?

There are many ways to control extending the image by 30 pixels from its border. It can just be the last pixel repeated out, it can be any color, it can be the last 30 pixels but mirrored. see http://www.imagemagick.org/Usage/misc/#virtual-pixel

Here are two examples (note your original image was not 1000x1000 but 1000x667):

repeated the edge pixel for 30 pixels:
convert original.jpg \
\( -clone 0 -blur 10x4 -fill white -colorize 30% -set option:distort:viewport 1060x727-30-30 \
-virtual-pixel edge -distort SRT 0 \) \
\( -clone 0 -bordercolor white -border 1 \) \
-delete 0 -gravity center -compose over -composite \
original_edge.jpg
http://www.fmwconcepts.com/misc_tests/b ... l_edge.jpg

mirroring the outer 30 pixels:
convert original.jpg \
\( -clone 0 -blur 10x4 -fill white -colorize 30% -set option:distort:viewport 1060x727-30-30 \
-virtual-pixel mirror -distort SRT 0 \) \
\( -clone 0 -bordercolor white -border 1 \) \
-delete 0 -gravity center -compose over -composite \
original_mirror.jpg
http://www.fmwconcepts.com/misc_tests/b ... mirror.jpg



___________________________________________
Thanks for the script. I see, you use

do shell script "/opt/local/bin/convert ....

That was what I had forgotten. The rest kind of looks familiar. Of course you have to deal with double backslashes and alternating single and double quotes, etc as before.

Re: Blurred border using Mogrify

Posted: 2009-04-19T22:29:27-07:00
by kilowatt
fmw42 wrote:But from your example above, you get a doubling of the outer 30 pixels from the original image. That is very strange and to me not very desirable. Is that really what you want?
You are right, that's not really what i want.
fmw42 wrote:repeated the edge pixel for 30 pixels:
convert original.jpg \
\( -clone 0 -blur 10x4 -fill white -colorize 30% -set option:distort:viewport 1060x727-30-30 \
-virtual-pixel edge -distort SRT 0 \) \
\( -clone 0 -bordercolor white -border 1 \) \
-delete 0 -gravity center -compose over -composite \
original_edge.jpg
http://www.fmwconcepts.com/misc_tests/b ... l_edge.jpg
This is really what I want! Thanks!

___________________________________________
fmw42 wrote:Thanks for the script. I see, you use

do shell script "/opt/local/bin/convert ....
You're wellcome... It took me a day to find out, I had to use full paths. It's the first time I use AppleScript.

Re: Blurred border using Mogrify

Posted: 2009-04-22T00:12:52-07:00
by anthony
I have added the above to the "Self Framing" examples in the Im Examples Thumbnails section
http://www.imagemagick.org/Usage/thumbnails/#self_frame
(may take a day or two to appear on the official web site)

However using a virtual-pixel edge can cause undesirable framing.

For example if the image has a tree or leaves, or some other small object on the edge of the image being framed in this way, a 'edge' expandsion can cause that object be become larger, producing a streak in the frame.

Of course the blur will reduce this problem, but it can still be a problem for a automatic framing algorithm. Your mileage may vary.


In brighting the image for the frame, I also noted that you used 'colorize' to color the image. An alternative is to use +level 30%,100% instead. For older IMs without the reverse +level option, you can use -level -50%,100% instead, though it is less exact.

Re: Blurred border using Mogrify

Posted: 2009-04-24T11:31:25-07:00
by fmw42
I have created a script, imageborder, to do this and more at http://www.fmwconcepts.com/imagemagick/index.html

Re: Blurred border using Mogrify

Posted: 2009-04-26T18:07:24-07:00
by anthony
Subject: Blurred border using Mogrify
fmw42 wrote:I have created a script, imageborder, to do this and more at http://www.fmwconcepts.com/imagemagick/index.html
Nice. Mirror tile seems to work well, but Tile does not unless the image itself is tilable.

I would however also include and example of blurred VP random, As it looks to me that the 'random' example does not appear to be blurred very much!

A option to a solid 'average image color' that is then lightened or darkened may also be a nice addition.

A blurred VP dither should be particularly interesting, as the result will like random, especially with blur, but limiting the color selection to a pixel pseudo-randomly picked within 32 pixels of the currant virtual position. That is with blur you should still get basically the same colors as exists nearby, but randomized a bit. Should make a interesting self-frame example.

Re: Blurred border using Mogrify

Posted: 2009-04-26T18:34:49-07:00
by fmw42
anthony wrote: I would however also include and example of blurred VP random, As it looks to me that the 'random' example does not appear to be blurred very much!
It is blurred by the same amount as all the rest. But even at blur=12 (rather than 3), it does not show too much.
anthony wrote: A option to a solid 'average image color' that is then lightened or darkened may also be a nice addition.
I will check into that.
anthony wrote: A blurred VP dither should be particularly interesting, as the result will like random, especially with blur, but limiting the color selection to a pixel pseudo-randomly picked within 32 pixels of the currant virtual position. That is with blur you should still get basically the same colors as exists nearby, but randomized a bit. Should make a interesting self-frame example.
Yes I just tested that and will add that as an option and in my examples. It has a rather interesting but strange texture pattern.

Re: Blurred border using Mogrify

Posted: 2009-04-26T20:36:53-07:00
by anthony
Are you sure you are blurring random?

Oh I know what is happening you blur the IMAGE, then generate the virtual pixels. As such you get random pixels from a blured image.

For random and dither (or the others) I suggest you use the distrot to read the image with its virtual pixel border, THEN blur that image! that waht you generate the random pixels FIRST, then Blur.

For a VP edge, or even magnify, bluring first does not make a lot of difference, But it will make a BIG difference for VP random and dither. Almost equivalent as turning off the blur altogether!

Actually for mirror and tile blurring before or after distort to extract VP's can produce some very different results, as blurring after will also blur some of the original image into the border VP's.

PS: rimcolor probably is not a good name, separator or edgecolor may be better.

Re: Blurred border using Mogrify

Posted: 2009-04-26T21:06:32-07:00
by fmw42
Anthony wrote:Oh I know what is happening you blur the IMAGE, then generate the virtual pixels. As such you get random pixels from a blured image.
Yes, you are right. Doh! :oops:
Anthony wrote:For random and dither (or the others) I suggest you use the distrot to read the image with its virtual pixel border, THEN blur that image! that waht you generate the random pixels FIRST, then Blur.

What is distrot? If you mean use -distort to read first then blur, then I agree. I was not looking carefully enough when I decided to add other VP methods after the main edge and mirror ones that are the most useful. Thanks for catching that.

I will work on all these changes tomorrow.

Re: Blurred border using Mogrify

Posted: 2010-06-14T14:25:53-07:00
by dehein2
Hi,
im trying to combine this skript (http://tomyeah.com/lightroom-post-proce ... agemagick/) for Lightroom with the frame described here, but i dont geht it to work.
Both skripts work on their own; the first one:

Code: Select all

@echo off
echo Processing…
:loop
if “%1”==”” goto endloop
if exist %1 call “E:\Programme\ImageMagick-6.3.5-Q8\convert.exe” -unsharp 0.3×0.4+0.45+0.05 -unsharp 0.2×0.3+2.0+0.05 -bordercolor White -border 1×1 -bordercolor Black -border 30×30 %1 %1
shift
goto loop
:endloop
works with Lightroom (Post processing after Export)

the second one:

Code: Select all

convert P1030252.jpg ( +clone -blur 10x4 -fill white -colorize 30% ) ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 ) -composite ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 ) -compose screen -composite image.jpg
works with a single image ...

but i dont get the 2. one pasted in the 1. one :)
This is what i tried so far:

Code: Select all

@echo off
echo Processing...
:loop
if "%1"=="" goto endloop
if exist %1 call convert ( +clone -blur 10x4 -fill white -colorize 30% ) ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 ) -composite ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 ) -compose screen -composite %1 
shift
goto loop
:endloop
Im using Windows.

Can someone help me!? ;)
Thanks

Re: Blurred border using Mogrify

Posted: 2010-06-14T14:56:15-07:00
by snibgo
if exist %1 call convert ( +clone -blur 10x4 -fill white -colorize 30% ) ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 ) -composite ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 ) -compose screen -composite %1
That command has no input image, something to stand in for P1030252.jpg in the previous command. Perhaps it should be:
if exist %1 call convert %1 ( +clone -blur 10x4 -fill white -colorize 30% ) ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 30x30 ) -composite ( +clone -gamma 0 -shave 30x30 -bordercolor white -border 1x1 -bordercolor black -border 29x29 ) -compose screen -composite %1