# Extract a portion of an image

**URL:** <https://community.wolfram.com/t/extract-a-portion-of-an-image/15213>\
**Category:** Questions\
**Tags:** image-processing\
**Created:** [January 7, 2020, 8:50am UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213 "2020-01-07T08:50:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepam](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@deepam](https://community.wolfram.com/u/deepam)\
**Post date:** [January 7, 2020, 8:50am UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213/1 "2020-01-07T08:50:40Z")

</div>

I’ve got an image and I want to obtain the centerlines of the image. ([Input image](https://github.com/DeepaMahm/misc/blob/master/Bagah.jpeg))  
I could obtain the centerlines using the following commands

```
img = Input_image
gray = ImagePad[ImageCrop[ColorConvert[img, "Grayscale"], ImageDimensions[img] - 6],10]
bin = Binarize[gray, 0.07]
skeleton = Pruning[Pruning@Thinning[bin], 15]

```

Now, I would like to obtain the centerlines for a particular region of the original image ( the region below the white marking - [image](https://github.com/DeepaMahm/misc/blob/master/extract.png)).  
Could someone suggest how this can be done?

---

<div class="post-metadata">

**Author:** ![mikayele](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mikayele/32/18393_2.png) [@mikayele](https://community.wolfram.com/u/mikayele)\
**Post date:** [January 8, 2020, 4:12pm UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213/2 "2020-01-08T16:12:33Z")

</div>

I am not quite sure I completely understand your question, but if I did correctly, and you know which region you want to emphasize, you could do something like this.

 ![ScreenShot2020-01-08at20.03.35.png](https://global.discourse-cdn.com/wolfram/original/3X/0/f/0f34628117aa15844f31f8fab13d82ebaa847e70.png)

Click on the `Image` object and navigate to `Mask tool`:

 ![Masking.png](https://global.discourse-cdn.com/wolfram/original/3X/f/f/ff63949bd09ec91c0815e535c6068f67e0ec73fc.png)

Select the `Freehand shape`:

 ![ScreenShot2020-01-08at20.06.30.png](https://global.discourse-cdn.com/wolfram/original/2X/c/ced4eda49709f345f795087eae298633c8d25dd5.png)

Mark the region of your interest:

 ![ScreenShot2020-01-08at20.07.44.jpg](https://global.discourse-cdn.com/wolfram/original/2X/3/3aac2ac556e42e9d72bedcc6677259acf57031e9.jpeg)

And copy the selection as an `Image` object:

 ![ScreenShot2020-01-08at20.08.35.jpg](https://global.discourse-cdn.com/wolfram/original/3X/1/4/147533866d11b4c4478357faf4eccd8fdfb84139.jpeg)

Then, paste and store the copied image:

 ![ScreenShot2020-01-08at20.09.41.png](https://global.discourse-cdn.com/wolfram/original/2X/6/67b03f37c252edd037b89336d9be72be96e11b6c.png)

Then, use `RegionBinarize`:

 ![ScreenShot2020-01-08at20.10.40.png](https://global.discourse-cdn.com/wolfram/original/3X/2/e/2e1fbe4acce4b7efe74e2bb54068bf02a3080ccd.png)

You can play with threshold, but I hope you now have the idea how to do it. Note, that this only applies to the case when you know in prior and can do the manual segmentation, otherwise, if you want to do it programmatically, you will have to figure out what is your region of interest first.

Mikayel

---

<div class="post-metadata">

**Author:** ![rjbr21](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rjbr21/32/15912_2.png) [@rjbr21](https://community.wolfram.com/u/rjbr21)\
**Post date:** [October 18, 2021, 6:34am UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213/3 "2021-10-18T06:34:44Z")

</div>

I have accomplished all of what is shown here successfully but have not been able to restore the B/W region to its original. ColorConvert does not seem to be the answer. What I am after is just the large foot in the attached notebook. Could you help me with this last step? Thanks.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/b2bf2ee5-cddc-43e7-8b0f-f40870544db7)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [October 18, 2021, 2:31pm UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213/4 "2021-10-18T14:31:17Z")

</div>

Hi Roger,

To apply a mask to an image, use `ImageMultiply`.

```
ImageMultiply[img, reg]

```

---

<div class="post-metadata">

**Author:** ![rjbr21](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rjbr21/32/15912_2.png) [@rjbr21](https://community.wolfram.com/u/rjbr21)\
**Post date:** [October 19, 2021, 3:30am UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213/5 "2021-10-19T03:30:12Z")

</div>

That worked great, Thanks. But I still have the black background. I need that transparent. I will fiddle with Opacity to see if that works but if you have a better way please send it along.

---

<div class="post-metadata">

**Author:** ![rjbr21](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rjbr21/32/15912_2.png) [@rjbr21](https://community.wolfram.com/u/rjbr21)\
**Post date:** [October 19, 2021, 3:38am UTC](https://community.wolfram.com/t/extract-a-portion-of-an-image/15213/6 "2021-10-19T03:38:54Z")

</div>

AHA!! RemoveBackground did it. Problem solved!! Thanks

RJB
