Function for widget titles

You can modify your filter function to add the condition:

function html_widget_title( $title ) {
    if ( '' != $title ) { 
        $output="<img src="https://wordpress.stackexchange.com/images/title_".$title.'.png" alt="'.$title.'" title="'.$title.'"/>';
        return $output;
    } else {
        return $title;
    }
}
add_filter( 'widget_title', 'html_widget_title' );