How do I identify close matched regions from this vector?
Show older comments
Hello,
Just by looking at it I can tell that I have 4 different regions, 0 to 122 then 375 to 563, 1145 to 1292 and 1697 to 2242. This is based on how much one region "jumps" to another.
Is there any way in Matlab in which I can identify these regions from this vector?
Thank you
Accepted Answer
More Answers (1)
Image Analyst
on 20 Mar 2014
1 vote
What do you mean by identify? It seems like you just did when you described the range of values that each takes. Do you want the indexes of each class? Do you want those intensity ranges specified automatically depending on each vector, like as if you use kmeans() or something? You (or someone) tagged it with image Processing so do you want to do connected components analysis (useful if some regions in an intensity range are not touching each other)?
14 Comments
Image Analyst
on 21 Mar 2014
Edited: Image Analyst
on 21 Mar 2014
Why not just do
v1 = v(v<122);
inRange = v >= 375 & v <= 563;
v2 = v(inRange);
inRange = v >= 1145 & v <= 1292 ;
v3 = v(inRange);
inRange = v >= 1697 & v <= 2242;
v4 = v(inRange);
You're just extracting values in each range into their own new vector.
Is that what you want?
If you also want the locations of those in terms of what indexes they reside at you can get them from regionprops():
measurements = regionprops(logical(inRange), 'PixelIdxList');
indexes = [measurements.PixelIdxList];
Faraz
on 24 Mar 2014
Image Analyst
on 24 Mar 2014
I never did understand your approach there. The difference between my approach and Star Striders is that I just extracted according to the ranges you gave, though I have no idea where you got those numbers. He's giving you some way to find those numbers based on the input data, assuming you're looking for outliers. I didn't know you were looking for outliers, I thought they could be clusters, so that's how our approaches differ. Different interpretations are what you get when you just say "I have 4 different regions, 0 to 122 then 375 to 563, 1145 to 1292 and 1697 to 2242." without giving any context.
Star Strider
on 24 Mar 2014
I got the impression that Faraz had extracted the data of interest (I didn’t know it was from an image), it gave the vector he posted, and Faraz wants a programmatic way of extracting the data between the discontinuities. That’s what I provided.
I assume the data came from something like:
h1l = findobj('type','line');
x1d = get(h1l,'XData');
y1d = get(h1l,'YData');
but I actually have no idea.
I’m now totally lost.
Image Analyst
on 24 Mar 2014
I believe he had a list of areas from blobs that were found in an image and those areas were plotted with asterisks on a graph. Then for some reason wanted to turn the graph into an image and do something with it, that I never understood. I suggested to just work directly with the data (the areas themselves as numbers) but my suggestion didn't go over well.
Star Strider
on 24 Mar 2014
Edited: Star Strider
on 24 Mar 2014
I certainly agree with your approach. Start with the image and get the necessary data. I had no idea the vector here represented image data, since the context wasn’t familiar to me. (I read many of your answers out of interest, but thought this was removed from image processing.) I get the impression no suggestion would have gone over well.
At least I have a ready-to-post code snippet if a real data discontinuity problem presents itself!
Although ‘That was perfect and exactly what I was looking for.’ it remains unaccepted. Oh, well...
Faraz
on 25 Mar 2014
Star Strider
on 25 Mar 2014
Edited: Star Strider
on 25 Mar 2014
I’m still not quite sure I understand, but now I assume you are starting from a plot someone else provided (and not generated by MATLAB, in which situation you could get the information in it from a ‘.fig’ file), and you want to get the data from it.
I assumed your data always moved in one direction, because that’s what I observed. If you are having problems because the start is higher than the end in some segments, experiment with changing the find criteria in the dvd line to something like:
find( (dv > dvs(1)+1.96*dvs(2)) | (dv < dvs(1)-1.96*dvs(2)) )
That enlarges the criteria to the ±95% confidence limits instead of simply the upper limit. I can’t guarantee that will work since I don’t have access to your other data, but it’s a start. (Note that I changed the code slightly.)
And Thanks!
Faraz
on 26 Mar 2014
Image Analyst
on 26 Mar 2014
Star I think you see now that he's just plotting blob areas:
stats = regionprops(label, 'Area');
area = [stats.Area];
figure(1), plot(area(:),'.');
So it's basically a plot of blob area vs. the blob label (ID) number. To look at that plot/scatterplot and see clusters is not meaningful. The clusters are totally artificial because the "x" axis is the label number. Labels are assigned by going down your image. first start at column 1 and see if you hit a blob. Then do a region growing to classify that whole blob as blob #1. Then continue on down the row, moving over column by column finding blobs and assigning new label numbers as you encounter them. So I hope you see that the label ID number of a blob is rather arbitrary and not meaningful as far as clusters go. For example, let's take your image and turn it 90 degrees, then label and find areas and plot them. You're going to have different label numbers assigned to each blob, and the area vs. label number plot will be COMPLETELY DIFFERENT , even though the image has the very same blobs in it.
As an analogy let's say you were measuring the heights of two classes of people: young children (who will be short) and adults (tall). So we have two clusters of heights, short heights and tall heights. Now let's stand them all in a line with all the children on the left and all the adults on the right. Let's give them an ID number (label) that corresponds to their position in the line. Now plot the heights in a scatterplot. You'll see a cluster of points in the lower left of the plot (this represents the children) and a cluster of points in the upper right representing adults. You get two clusters. Interleave them (kid, adult, kid, adult, etc.) and you again get two clusters. But the clusters are along the height axis, any clusters appearing along the label axis are artificial. Now rearrange them again to have half the kids, half the adult, half the kids, and half the adults. Now the plot seems to show 4 clusters even though the set of heights didn't change! But you still have 2 clusters along heights and any clusters you see along the label axis are not real. Here's some code to illustrate that:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
c = [3,4,3,3.2,3.5,3.1] % child heights
a = [5.9, 6, 5.8, 6.1, 6.05, 5.95];
% Stand children on left, adulat on right.
allPersons = [c,a];
IDNumbers = 1 : length(allPersons);
subplot(3,1,1);
plot(IDNumbers, allPersons, 'b*', 'LineWidth', 4);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
title('Now you see 2 clusters along height and label.', 'fontSize', fontSize);
% Now interleave children and adults.
for k = 1 : 6
allPersons(2*k-1) = c(k);
allPersons(2*k) = a(k);
end
% Now it's kid, adult, kid, adult, kid, etc.
% Now plot
subplot(3,1,2);
plot(IDNumbers, allPersons, 'b*', 'LineWidth', 4);
grid on;
title('Now you see 2 clusters along height ONLY, not along label.', 'fontSize', fontSize);
% Now have 4 groups, 3 chilred, 3 adults, 3 children, 3 adults.
allPersons = [c(1:3), a(1:3), c(4:end), a(4:end)];
% Now plot
subplot(3,1,3);
plot(IDNumbers, allPersons, 'b*', 'LineWidth', 4);
grid on;
% Now you see 4 clusters along height and along label.
title('Now you see 4 clusters along height and along label.', 'fontSize', fontSize);

I hope this illustrates why finding clusters on an area vs label number plot is meaningless. You'd be better off just doing unsupervised clustering on the areas. Or pick a certain number of clusters and use kmeans.
Faraz
on 26 Mar 2014
Image Analyst
on 26 Mar 2014
OK. Maybe I misunderstood when you said here that you wanted to create an image from the plot of data points and gave code to do so. So now we agree that the plot doesn't matter, it's only the area values that matter, not what they look like when plotted, and there's no further image to deal with at all. So, what about clustering methods like kmeans? Can you try those? See this search http://www.mathworks.co.uk/matlabcentral/answers/?term=unsupervised+clustering
Star Strider
on 26 Mar 2014
I had to go read about regionprops and related functions, since I don’t do much image processing. (I intend to explore the File Exchange for demos and tutorials, but not just now.)
I feel as though I managed to jump into the middle of something here without knowing the wider context, and I’m still not certain I do. I always assume that Faraz and others who post here have designed their studies carefully, knowing how they intend to acquire and analyse their data, and post here for help in dealing with unanticipated problems. (Too often that is not the situation, and people decide to design their studies after they have gathered their data, but I did not get that impression here.)
I’m glad I could help, and I apologise for contributing to any confusion.
Image Analyst
on 26 Mar 2014
You've been very helpful. It can get confusing when people don't give the whole context so we don't know what the big picture is. Even more frustrating is when you know the big picture but people are dead set on going down a path that you know is a dead end , and when you suggest a workable approach they continue to try their dead end approach.
Categories
Find more on Creating and Concatenating Matrices 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!
