Can morphology be applied to the selected color?

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
Posts: 3
Joined: 2020-02-02T09:54:42-07:00
Authentication code: 1152

Can morphology be applied to the selected color?

Post by tablo21 »

in order to achieve the final result, I have to give 20 different imagemagick commands. total time ~ 14 seconds. I want to reduce this time. asking only areas where morphology is to be applied.

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

Re: Can morphology be applied to the selected color?

Post by fmw42 »

I do not understand your question. Please post a link to an image and show your commands. Also what is your ImageMagick version and platform?

Posts: 12897
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can morphology be applied to the selected color?

Post by snibgo »

The question is too vague.

Morphology can be restricted to a single channel. Perhaps you can transform your "selected colour" to one channel.

It would help if you showed example images.
snibgo's IM pages:

Posts: 3
Joined: 2020-02-02T09:54:42-07:00
Authentication code: 1152

Re: Can morphology be applied to the selected color?

Post by tablo21 »

Windows 7 64

my imagemagick :

F:\pp>magick -version
Version: ImageMagick 7.0.8-23 Q16 x64 2019-01-02
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangoc
airo png ps raw rsvg tiff webp xml zlib

inputfile :

;so i get a 2 picture... FastFind.dll
; original screenshot
FFSnapShot ( $posGame[0], $posGame[1], $posGame[2], $posGame[3],$slot2 ,0) ; scrinshot area fullcolor to memory
FFSaveBMP(C:\img\screen2' ,False) ; save from C:\img\screen2.bmp

; Screenshot of the original using color restrictions
Local $aColors[6] = [0xA2A2B3,0xC2C2D6, 0xC8C8DC, 0xB0B0C2, 0x9B9BAB,0x9393A2] ; color text
FFAddColor($aColors) ; add base color text filter
; FFSnapShot ([Left [, Top [, Right [, Bottom [, NoSnapShot [, WindowHandle]]]]]])
FFSnapShot ( $posGame[0], $posGame[1], $posGame[2], $posGame[3],$slot2 ,0) ; scrinshot area fullcolor to memory
FFKeepColor(-1, 7, False) ; We leave only the necessary colors from the list of $ aColors and fat colors
FFSaveBMP(C:\img\screen3' ,False) ; save from C:\img\screen3.bmp

; :?: Can I take a screenshot of imagemagick and save more image data? :?: alfa channel etc.

; ---------- it's time for magic -----------
Magick convert с:\img\screen3.bmp -morphology Dilate Rectangle:13x13 \ -negate с:\img\screen3_obraz5.png
Magick convert с:\img\screen3_obraz5.png -morphology close rectangle:1x21 с:\img\W1.png
Magick convert с:\img\screen3_obraz5.png -morphology close rectangle:40x1 с:\img\H1.png
Magick convert с:\img\W1.png с:\img\H1.png -compose plus -composite \ -negate -threshold 0 с:\img\ramka.png
; remove very small
Magick convert с:\img\ramka.png -fill black +opaque white -type bilevel \ -define connected-components:mean-color=true \
\ -define connected-components:area-threshold=1000 \ -connected-components 4 с:\img\ramka_mask.png
; I have a great desire to combine in 1 line for magic

; mask for photographing is ready

; get information about the coordinates of objects in the terminal
Magick c:\img\ramka_mask.png -define connected-components:verbose=true -connected-components 4 c:\img\objectOK.png

; writing response in terminal in null.txt. I did not conduct the full syntax of the code - I left only magic commands
; ; Null.txt

; I get the coordinates from null.txt and crop and resize *2

; do

Magick convert с:\img\screen3.bmp -crop '&$crd[$i][2]&'x'&$crd[$i][3]&'+'&$crd[$i][0]-$crd[$i][2]/2&'+'&$crd[$i][1]-$crd[$i][3]/2&'\
\ -resize '&$crd[$i][2]*2&'x'&$crd[$i][3]*2&' с:\img\txt\txt_'&$i&'.png
; tasseract с:\img\txt\txt_'&$i&'.png and save result с:\img\txt\txt_'&$i&'.txt
; until end coord

I do a cycle in which I give the magic command then a tesseract, but I think this is not correct! It is better to first work out the magic and prepare the files for tesseract processing.

PS: if you use cropping from the original screen2.bmp, the capture areas do not match much, because the mask is created based on the font color. I made a more correct mask based on black rectangles, but still have not figured out how to color the neighboring regions I need. ... =1&t=37488

result files


Post Reply