Hello All,
I have a image where i have drown a boundry of specific color, and i want to now crop this image and have only those part of the image which is inside that specific boundry.
Ex:
I have a image of world map and i want cropped image of particular country (Ex. India) whose boundry is drawn with Yellow Color.
The resultant image should only contain the India's map and all the other part of the image can be made blank.
Can somebody suggest the command which i can use for this, Ideally i believe there should some command which find the boundary of particular hash code of color and given the inner part of that boundry as a image.
Thanks in advance for your help
Crop Image within the border of specific color
-
- Posts: 4
- Joined: 2019-08-14T07:43:16-07:00
- Authentication code: 1152
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Crop Image within the border of specific color
What version of IM, on what platform? Sample input image?
One method would be to flood-fill from the top-left corner with yellow. Then trim.
One method would be to flood-fill from the top-left corner with yellow. Then trim.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Crop Image within the border of specific color
Please post an image. You will need to upload to some free hosting service and put the URL here.
-
- Posts: 4
- Joined: 2019-08-14T07:43:16-07:00
- Authentication code: 1152
Re: Crop Image within the border of specific color
Following is the image:
https://ibb.co/3pHgn6S
Here i just want the inner part of the dark yellow boundry
https://ibb.co/3pHgn6S
Here i just want the inner part of the dark yellow boundry
-
- Posts: 4
- Joined: 2019-08-14T07:43:16-07:00
- Authentication code: 1152
Re: Crop Image within the border of specific color
I am using following exe from Imagemagick site
ImageMagick-7.0.8-60-Q16-HDRI-x64-dll.exe
And yes i am doing it on windows Machine
ImageMagick-7.0.8-60-Q16-HDRI-x64-dll.exe
And yes i am doing it on windows Machine
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Crop Image within the border of specific color
This is in Unix. One of the Windows users can give you the equivalent.
The technique is to clone the image to make a mask. In the clone, make anything not yellow into black and everything else white. Then flood fill from the center with white to make everything inside the yellow area including the yellow into white. Then put the mask into the alpha channel of the original image.
Input:
In Windows, remove the \ from the parentheses. Change the end of line \ to ^. Fill in the $centx,$centy with the center values so that you can ignore the declare line. Otherwise, a Windows user will need to show you the equivalent code for creating and using variables.
The technique is to clone the image to make a mask. In the clone, make anything not yellow into black and everything else white. Then flood fill from the center with white to make everything inside the yellow area including the yellow into white. Then put the mask into the alpha channel of the original image.
Input:
Code: Select all
declare $(magick GIS-County.jpg -format "centx=%[fx:w/2]\ncenty=%[fx:h/2]" info:)
magick GIS-County.jpg \
\( -clone 0 -fuzz 15% -fill black +opaque "rgb(243,246,67)" -fill white +opaque black \
-fill white -draw "color $centx,$centy floodfill" \) \
-alpha off -compose copy_opacity -composite \
GIS-County_result.png
In Windows, remove the \ from the parentheses. Change the end of line \ to ^. Fill in the $centx,$centy with the center values so that you can ignore the declare line. Otherwise, a Windows user will need to show you the equivalent code for creating and using variables.
-
- Posts: 4
- Joined: 2019-08-14T07:43:16-07:00
- Authentication code: 1152
Re: Crop Image within the border of specific color
Hey fmw42,
Thank you very much for your response, your script was very helpful.
Thank you very much for your response, your script was very helpful.