My background is in guitar, but a few years ago when my daughter started taking piano lessons, I started spending a bit of time stretching musically on the piano. I have a friend with a degree in improvisation who suggested I investigate “guide tones”. Guide tones are basically the 3rd and 7th of the currently playing chord. So if I was playing a C Major chord, the guide tones would be E and B. You try to play guide tones on the strong beats, and more dissonant notes on the weak beats. This simple rule makes for a great starting point for improvising melodies over a chord progressing.
But it turns out you can use the reverse process to identify a chord to fit under an existing melody. So if a melody has an E on a strong beat, you could use C Major (where E is the 3rd) or F Maj7 (where E is the 7th) if you wanted to stay in the key of C Major. You can really stretch out harmonically by throwing away the notion of a key, and playing any chord where E was the 3rd or 7th – Like C# Minor or F#7. Once you stray out of a key using this technique, you can generally steer back into your key by going to the dominant chord (G7 in this example), then back to C Major. Of course, you could also try to see if your out-of-key chord is the secondary dominant of another chord in the key and get back into your key by resolving to that other chord. For a more adventurous chording, you might throw away the key entirely for your accompaniment and just choose from the possible chords based on what sounds good and fits into the 3rd or 7th of the melody.
It has been hours and hours of fun for me. Why not give it a try?