To extract the modified sector with original size

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
trexmernii
Posts: 6
Joined: 2017-03-30T14:03:59-07:00
Authentication code: 1151

To extract the modified sector with original size

Post by trexmernii »

Hi!

I have two png file:
  • Original autosize_wet.png
Image
  • Original with the changes autosize_wet_change.png
Image

I need to extract the modified sector. The size of the file(height and width) must not change

At now I find change

Code: Select all

convert autosize_wet_change.png autosize_wet.png -compose ChangeMask -composite autosize_wet_comp.png
  • autosize_wet_comp.png
Image

But I need this image:
  • autosize_wet_change_sector.png
Image

How to extract the modified sector with original size?

Any ideas?

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: To extract the modified sector with original size

Post by fmw42 »

What is your IM version and platform? Please always provide that infomation.

You say that the size of the file must not change. Yet, your desired result is neither the width or height of your input image. So what exactly are you after? Just the bounding box of the difference area? If so, then try (assuming IM 6 Unix)

Code: Select all

bbox=`convert 7c891639bfe0.png 76d7a80f34da.png -compose difference -composite -threshold 0 -format "%@" info:`
convert 76d7a80f34da.png -crop $bbox +repage result.png
trexmernii
Posts: 6
Joined: 2017-03-30T14:03:59-07:00
Authentication code: 1151

Re: To extract the modified sector with original size

Post by trexmernii »

Platform: Windows (VB)
Im version: 7.0.5-Q16

Work

Code: Select all

Sub convert()

Dim original As String
Dim difference As String
Dim output As String
Dim wh_orig As String
Dim wh_dif As String
Dim IM As String

Dim y As Integer

IM = "C:\Program Files\ImageMagick-7.0.5-Q16\magick.exe"
original = "K:\autosize_wet.png"
difference = "K:\autosize_wet_change.png"
output = "K:\autosize_wet_result.png"

wh_orig = Run_ImageMagick("""" & IM & """ convert """ & original & """ -format ""%G"" info:""")
wh_dif = Run_ImageMagick("""" & IM & """ convert """ & original & """ """ & difference & """ -compose difference -composite -threshold 0 -format ""%@"" info:""")
Run_ImageMagick """" & IM & """ convert """ & difference & """ -crop " & wh_dif & " +repage """ & output & """"

y = InStr(1, wh_dif, "+")
wh_dif = Mid(wh_dif, y, Len(wh_dif) - y + 1)

wh_orig = wh_orig & wh_dif

Run_ImageMagick """" & IM & """ convert """ & output & """ -set page " & wh_orig & " -background transparent -flatten """ & output & """"

End Sub

Public Function Run_ImageMagick(Send As String) As String

Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec(Send)
Set OutStream = WshExec.StdOut

Dim str As String
    While Not OutStream.AtEndOfStream
        str = str & Trim(OutStream.ReadLine())
    Wend
    
Run_ImageMagick = str
End Function
Last edited by trexmernii on 2017-04-01T02:44:10-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: To extract the modified sector with original size

Post by fmw42 »

Have you tried the Window equivalent of my command? You did not answer my questions. Your statements are confusing about the size.
trexmernii
Posts: 6
Joined: 2017-03-30T14:03:59-07:00
Authentication code: 1151

Re: To extract the modified sector with original size

Post by trexmernii »

Yes. Aded a couple of lines to your code.
Its mission is described thoroughly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: To extract the modified sector with original size

Post by fmw42 »

Sorry, I do not read your code. If my command works, then fine. If not, then you need to explain what output size you want.
trexmernii
Posts: 6
Joined: 2017-03-30T14:03:59-07:00
Authentication code: 1151

Re: To extract the modified sector with original size

Post by trexmernii »

Original size autosize_wet.png 450x94.
Yor result.png 68x64.

My result.png 450x94.
trexmernii
Posts: 6
Joined: 2017-03-30T14:03:59-07:00
Authentication code: 1151

Re: To extract the modified sector with original size

Post by trexmernii »

oic - original image size

Code: Select all

oic =`convert 7c891639bfe0.png -format "%G" info:`  
--oic =450x94

bbox=`convert 7c891639bfe0.png 76d7a80f34da.png -compose difference -composite -threshold 0 -format "%@" info:` 
--bbox=64x68+225+12
--don't know how to do it Unix   oic=450x94+225+12

convert 76d7a80f34da.png -crop $bbox +repage result.png
convert result.png -set page $oic -background transparent -flatten result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: To extract the modified sector with original size

Post by fmw42 »

Try this

Code: Select all

bbox=`convert 7c891639bfe0.png 76d7a80f34da.png -compose difference -composite -threshold 0 -format "%@" info:`
convert 76d7a80f34da.png -crop $bbox -background none -flatten result.png
trexmernii
Posts: 6
Joined: 2017-03-30T14:03:59-07:00
Authentication code: 1151

Re: To extract the modified sector with original size

Post by trexmernii »

Excellent!
Thank you very much!
Post Reply