Page 1 of 1

To extract the modified sector with original size

Posted: 2017-03-30T14:30:26-07:00
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

Re: To extract the modified sector with original size

Posted: 2017-03-30T15:07:28-07:00
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

Re: To extract the modified sector with original size

Posted: 2017-03-31T17:00:29-07:00
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

Re: To extract the modified sector with original size

Posted: 2017-03-31T17:51:41-07:00
by fmw42
Have you tried the Window equivalent of my command? You did not answer my questions. Your statements are confusing about the size.

Re: To extract the modified sector with original size

Posted: 2017-03-31T22:58:11-07:00
by trexmernii
Yes. Aded a couple of lines to your code.
Its mission is described thoroughly.

Re: To extract the modified sector with original size

Posted: 2017-03-31T23:16:56-07:00
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.

Re: To extract the modified sector with original size

Posted: 2017-03-31T23:48:04-07:00
by trexmernii
Original size autosize_wet.png 450x94.
Yor result.png 68x64.

My result.png 450x94.

Re: To extract the modified sector with original size

Posted: 2017-04-01T00:02:26-07:00
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

Re: To extract the modified sector with original size

Posted: 2017-04-01T10:35:00-07:00
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

Re: To extract the modified sector with original size

Posted: 2017-04-01T12:27:38-07:00
by trexmernii
Excellent!
Thank you very much!