Display a list of subcategories a post belongs to

Here is a function I’ve recently used (modified version of the code found in the codex) to display a list of the categories a post is attached to.

This function first gets the parent category to which the post belong, and that info is then fed back into wp_list_categories to remove the parent category and to get a list of the child categories belonging to that parent

<?php 
$taxonomy = 'category';

// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator=", ";
$categories = get_the_category();
$parentid = $categories[0]->category_parent;

if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {

    $term_ids = implode( ',' , $post_terms );
    $terms = wp_list_categories( 'title_li=&style=none&echo=0&child_of=" . $parentid . "&taxonomy=' . $taxonomy . '&include=" . $term_ids );
    $terms = rtrim( trim( str_replace( "<br />',  $separator, $terms ) ), $separator );

    // display post categories
    echo  $terms;
}
?>