JuliaImages / ImageSegmentation.jl

Partitioning images into meaningful regions
Other
47 stars 23 forks source link

output or convert a segmented image #9

Closed Ken-B closed 7 years ago

Ken-B commented 7 years ago

First of all, thank you both for all the good work you are doing! I'm no expert but I require some image segmentation for my work and I am very happy to see the progress. I'm especially looking forward to the mean shift algorithm.

For this issue, I wonder why the output type SegmentedImage does not contain an actual segmented image (unless I'm missing it)? Could you perhaps include a conversion function? At the moment I'm using the following:

valuetype{K,V}(d::Dict{K,V}) = V

function make_image(segm_im::ImageSegmentation.SegmentedImage)
    labels  = segm_im.image_indexmap
    means   = segm_im.segment_means
    imgsegm = zeros(valuetype(means), size(labels))
    for i in eachindex(imgsegm)
        imgsegm[i] = means[labels[i]]
    end
    imgsegm
end

Thank you. And let me know if and where I can assist.

annimesh2809 commented 7 years ago

@Ken-B Thanks for praising our work! :smile:

The term "actual segmented image" is a little unclear. Any segmentation algorithm partitions an image by assigning each pixel of the image to a specific label. Hence, the result of a segmentation can be conveyed through the Dict(Pixel => Label) (image_indexmap) alone.

If you are interested in the image generated by replacing each label in image_indexmap to its corresponding mean color, then you could try this:

julia> # seg is a `SegmentedImage`
         seg_means = map(i->seg.segment_means[i], seg.image_indexmap)
Ken-B commented 7 years ago

Thanks, that clarifies. The oneliner is more elegant than my function.