How to do image segmentation of a beam?

How to use image segmentation to select the whole light beam?
My final aim is to select the whole beam using image segmentation and then calcuate the minimum intensity point (center here but not necessary in other images) and plot it in an XY cartesian cordinate plane.

9 Comments

Hi!
How do you define intensity of the beam in terms of image pixels?
Also share the image as attachment for clarity.
If you need help processing an image, attach the actual image -- not a screenshot of a pseudocolor representation of the image.
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1473236/image.png');
inpict = imcrop(inpict,[278 73 648 654]); % stop working with screenshots
% stop working in pseudocolor
CTref = mycolortable(256); % this is only an ESTIMATE of the original colormap
outpict = rgb2ind(inpict,CTref); % an estimate derived from another estimate
imshow(outpict,'border','tight')
All of this is merely to estimate what the original image used to be.
Similarly, you say you want to find some unique minimum value point. In this image, the center is the exact same value as the surrounding background. While it might be easy enough to say that we want the minimum point on the interior of the ring, you say that the other images don't always follow this same shape. ... So what shape do they follow? If the minima are not unique, and we don't know what regions are relevant or how they're shaped, there isn't enough information to know how to select the right spot.
If you have images that vary, you'll need to provide some sort of description of how they vary and what point is the point of interest. The simplest way to describe this is by including relevant example images.
While it shouldn't be necessary to solve the work at hand, I personally would like to know what colormap you used to visualize the image. I've seen it used a few times, but I've never been able to identify the source or get an exact copy. What I used above is an estimate I calculated based on another image:
@DGM you might like the ODYSSEA colormap, attached.
I'm not looking for a similar map. I'm looking for the exact same map, such as would allow these sorts of pseudocolor images to be back-calculated as accurately as possible. I accept that de-colorzing a pseudocolor representation of data is a horrible sinful thing that should never have to happen in any sane workflow, but we all know where we are.
ODYSSEA:
MYSTERY MAP (both the given beam image and the estimate from mycolormap.m:
The map is similar to the 'spectrum' map from MatPlotLib, but it's distinctly different at the top end, and the suggestion that it's derived from somewhere else yet suggests the rabbit hole is deeper than what I've explored so far. I've tried to refine my estimate as time goes by, but it's still pretty wrinkly for what appears to be a simple PWL trajectory.
I think it's impossible to get the colormap used to colorize a grayscale image. For any given gray scale image, I could get 100 or more colorized images that look totally different, and it would be impossible to take any one of those pseudocolored images and "undo" it to get back the original gray scale image, unless you knew something about the image (like it had a linear gray scale ramp or step wedge in it).
DGM
DGM on 7 Sep 2023
Edited: DGM on 7 Sep 2023
Well, we've seen at least a couple images that contained a colorbar (they were all JPG iirc), so that gives us some ordinal information. The rest is a matter of reinforcement. I think it's safe to assume that the trajectory is piecewise in RGB, but I'm not certain that it's entirely PWL. Averaging the cloud of colors from the observed images doesn't really help. The "refinement" is more a matter of trying to see if any one image gives a clearer indication of the breakpoint locations and trying to tuck the curves closer to the presumed breakpoints.
Given that this is a geometrically simple image in a lossless format, I would expect it to yield a very useful sample. While it's very good, there are quite a few rounded corners and wiggles in the trajectory. I'm doubting that it's generated from its breakpoints. I expect that the file that generates the requested CT starts with a full (e.g. 256-level) CT and interpolates up or down as necessary. Much like parula(), turbo(), etc, I suspect that the function that generates the CT doesn't actually reveal much about its development. In all likelihood, the canonical trajectory is just as wiggly and imperfect.
Again, you know how I complain about keeping screenshots, lossy compression, and guesswork out of technical (an non-technical!) workflows, but I also like to hit the ground running with an example, even if it's not satisfactory. Half the time, we never get enough followup information to make anything better than these demonstrative estimates based on junk sources.
U B
U B on 7 Sep 2023
Edited: U B on 7 Sep 2023
I shoud have attached the actual files. The attached images are bmp images with hot colormap.
As you can see in the '90.bmp', the minimum intensity is at the center but the backgroung of the image is also null, so image sagmentation can be a way to select only the beam and then read the image where the value is zero. A patch of pixels from the centre will have null value.
In the 2nd image '88.bmp' there are two null (area) points. Can we go ahead in the same way here and calculate the null position or area inside the beam? I apriciate your input on this.
About the colormap I was using before, it was not an inbuilt colormap. We customised it with certain value of color for our need. We call it RainbowColormap256.
Uh, thanks. But why couldn't you attach the original gray scale (non-colorized) image? That would save us the trouble of having to undo the colormap.

Sign in to comment.

Answers (1)

Oog. I'm answering with gloves on, so this is hasty.
First, a preliminary solution:
% we should be working with 2D data, not RGB
[inpict,map] = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1475201/88.bmp');
% map is close, but not quite exactly the same as hot(256);
% dunno what's going on there or why
% going to treat the index array as a grayscale image (again, not a good idea)
% after this point, we're working with 2D grayscale data.
% that's where we should be starting in practice.
inpict = mat2gray(inpict);
% assume that the bg is a minimal region
% assume that the bg is connected to the image boundary,
% but not connected to the interior minima
bgmask = inpict == inpict(1,1); % find the background
% i'm assuming that the interior minima are always
% exactly the same value as the exterior minima
% so re-find the minima only within the fg region
bgmask = imclearborder(bgmask);
% get the centroids of the interior minima
S = regionprops(bgmask,'centroid');
C = vertcat(S.Centroid);
% display the things
imshow(inpict); hold on
plot(C(:,1),C(:,2),'x','linewidth',2)
Two things:
We still don't want to work with colormapped (pseudocolor) images. The colormapping is a tool for human visualization, but it's not helpful for the actual programmatic processing of the image. The images we should be working with are simple 2D grayscale data. They might be on some arbitrary scale, and they might not be stored in what we might consider an "image file" format, but conceptually, they're just 2D data.
Second (and this is entirely optional and inconsequential to the solution), could you attach the .m file used to generate said colormap?

Categories

Find more on Images in Help Center and File Exchange

Asked:

U B
on 5 Sep 2023

Commented:

on 7 Sep 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!