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
tablo21
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
fmw42
Posts: 26292
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?

snibgo
Posts: 12937
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: im.snibgo.com

tablo21
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 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
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 :
https://cloud.mail.ru/public/3GTV/4B9ZVRje5

;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
https://cloud.mail.ru/public/4aq7/kGpC33D3V

; 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
https://cloud.mail.ru/public/qZdi/3oVpZZMVD

;~~~~~~~~~~~~~~~~~~
; :?: 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
https://cloud.mail.ru/public/4BF6/5847rQYuw
https://cloud.mail.ru/public/3xJ8/znEnRB1ga
https://cloud.mail.ru/public/49VR/2dQ1tqMjT
https://cloud.mail.ru/public/3RvX/4LcgVcvU4
https://cloud.mail.ru/public/5hgz/4Af4NPmBz

; 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
;
https://cloud.mail.ru/public/CG5N/2hM5L2XKn ; 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.
https://imagemagick.org/discourse-serve ... =1&t=37488


result files
https://cloud.mail.ru/public/3WAZ/2JA2rUtV3

video
https://cloud.mail.ru/public/4nUv/37GznjWco

Post Reply