Trying to display the segmentation result in the same type as of the original image.
2 views (last 30 days)
I have applied basic segmentation on my image. 's1.png' is the original image and 's2.png' is the segmented image. I want the segmented image to be of the same type(color) as the original image. However, I am unable to do it. Any suggestions would be appreciated.
se = strel('disk',10);
closeBW = imclose(m,se);
level = multithresh(closeBW);
seg_I = imquantize(closeBW,level);
DGM on 2 Nov 2022
Edited: DGM on 2 Nov 2022
I think you might be asking how to programmatically cast and scale an image to a specific class from any class. If that's the case, then this is how you'd do it within the scope of base MATLAB/IPT:
% say we want to cast/scale image FG to have the same class as image BG
outclass = class(BG);
FG = im2uint8(FG);
FG = im2double(FG);
FG = im2single(FG);
FG = im2uint16(FG);
FG = im2int16(FG);
FG = logical(FG); % this is a great way to create problems
error('some error message goes here')
... because the primary parameter (the class name) is embedded in the function names. It's almost like you're being tempted to use eval() or something.
You could also use cast(), which does support the class name as a parameter, but then you'll have to take care to correctly scale the data for each possible combination, because cast() doesn't scale anything.
... or you can just use MIMT imcast():
FG = imcast(FG,class(BG));
That said, you might presume that your input image is uint8 and just use im2uint8(). That's certainly fallible,but it's simple and might cover your needs.