Paint by numbers with Matlab. Imcontour function
Show older comments
Hi! I am working for my diploma project and I encounter some difficulties. I am trying to make a paint by number program where you put an image and the program shows the contour of the colors and the colorbar. Also I want to label every area of the contour with the number of the color that is in that area. I have managed to do this but it's not the result I am expecting. As you can see in the image below, the labels of the colors are on the lines and not on the contoured area and the colorbar is a gradient and not separate colors as they are in the colorbar of an indexed image. How can I make more accurate contour regions and to label them in the middle of the region not on the line? How can I make the colorbar to appear as separate colors and not as a gradient?

[IND,map] = rgb2ind(I,10);
imagesc(app.UIAxes, I);
s=colorbar(app.UIAxes);
colormap(app.UIAxes,map);
imshow(I,'Parent',app.UIAxes);
I2=ind2gray(IND,map);
colormap(app.UIAxes, map);
axis image;
%imshow(I2,'Parent',app.UIAxes);
[C,h]=imcontour(I2,'-k');
clabel(C,h)
colorbar;
1 Comment
DGM
on 2 Jul 2021
For the colorbar, make sure to assert
colormap(axeshandle,map)
after you run imcontour().
That said, the difficulty of figuring out how to move the labels leaves me thinking that using contour() probably isn't the simplest way to do this. I might think about that one for a bit.
Accepted Answer
More Answers (0)
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

