How to create a linkage between different blob?

For example I using watershed and get different color piece.
I want to create a matrix to show the linkage.
1 1 1 1 1 1 1 1 1 1 1
1 2 2 1 3 3 1 4 4 0 1
1 2 1 3 3 1 0 4 4 0 1
1 1 1 1 1 1 1 1 1 1 1
so when loop vertical and horizontal I wish to get the result like matrix.jpg
I want check before 1 and after 1,
if check got 2,3 so return 1 to matrix(3,2)=1 matrix(2,3)=1
if check got 3,4 so return 1 to matrix(3,4)=1 matrix(4,3)=1
if 0 then ignore.
How to do this?

6 Comments

I have no idea what you're asking and I've read it multiple times.
Basically I got an watershed image and I bwlabel and labelrgb2 it so I got many color blob label 1 to n.
Now I want to create a table to show the color blob connected beside it like table.jpg.
So I create a matrix(1,n) all 0 at first, when check connectivity then only update those blob which connected into 1.
example blob .jpg
255 255 255 255 255
255 001 255 002 255
255 255 255 255 255
255 003 255 255 255
so when I loop horizontal cur=1, if meet 255, next=2 so mean blob 1 and 2 is connected
I want update table(1,2)=1 table(2,1)=1
after loop horizontally and next loop vertically so found blob 1 and blob 3 is connected so update table(1,3) table(3,1)=1.
What I want to get is the table that show which label blob connected with which label blob like table.jpg.
I would have understood better if your table had showed 1 at entries (1,3) and (3,1)
With the updated table then I am fairly sure glcm can be used.
now I get the relationship table so I decide to merge them together based on the original image color pixel.
example blob.jpg:
blob 1(rgb=122,122,122) and blob 2(rgb=121,121,121) the color is nearly same(threshold maybe set to rgb+-10) so I reassign label blob 2 to label blob 1.
blob 3 maybe pixel value(10,12,13) on original image is huge different with blob 1 so I decide not merge to blob 1.
Problem I faced now is how to compare matrix of color blob (x,y)position with matrix impixel of original image so I can decide whether want to merge different blob together or not?
You need to define when two colors are "nearly the same" or not. It is not an easy question, especially when you are working with the darker colors. For example, is [10,0,0] "nearly the same" as [0,0,0] because the values are within 10, or is [10,0,0] definitely "red" whereas [0,0,0] is "black" ?
You should look for some of what Image Analyst has posted about "Delta E"

Sign in to comment.

 Accepted Answer

Use glcm on the blob numbers. This will give you counts instead of just yes/no, but you can get the yes/no by just testing whether the count > 0.

5 Comments

row_pairs = [reshape(A(:,1:end-1),[],1), reshape(A(:,2:end),[],1)];
col_pairs = [reshape(A(1:end-1,:),[],1), reshape(A(2:end,:),[],1)];
upairs = unique([row_pairs; col_pairs], 'rows');
maxblob = max(upairs(:));
blob_table = false(maxblob, maxblob);
blob_table( upairs(:,1) + (upairs(:,2)-1)*maxblob ) = true;
blob_table( upairs(:,2) + (upairs(:,1)-1)*maxblob ) = true;
Tan's question has nothing whatsoever to do with what he asking. It has nothing at all to do with delta E or merging blobs of the same color or adjacent blobs. He just asked a question without supplying context of prior questions. It's the old case of "Tell me how to do X" and then you say how to do X and then the poster says that it didn't work, and you say "Why not" and they say "Well because I want to do Y", after which you say, "well if you want to do Y, you definitely don't want to do X, you need to do Z".
Basically he wants to separate the two elephants in this labeled image:
So he started with the faulty premise that watershed would do the best job - and that's where all the trouble started. Watershed is notorious for over-segmenting regions, and then you have to do special tricks to repair that. Then he wants to "decide to merge them together based on the original image color pixel." But it appears from his comments that the colors he calls original are the pseudocolor label colors, not the original RGB image, so this is destined to fail. If anything he should look at the original RGB mean colors in each labeled region, not the arbitrary labeled image colors.
Or better yet, just use something like this:
Because I never learn image proccesing before~so my question is maybe seem ignorance to the you guy.I just follow step by step my lecturer ask me do so can teach me how to do the comparing?
I want comparing the relationship table with original image rgb, not the pseudocolor label.
So I need compare the position of color blob with position of original image.example blob 1 and blob 2 in original image is grey so I change the pseudocolor label of blob 2 to blob 1.
Beside using watershed what else method can use to get the color blob? i just want to get some simple segmentation~what I do is just follow my lecturer say~I left 1week to get this thing done~any simple method can help me?
If you have a function that can return whether two rgb colors are "close" or not, then you pass in to that table the pseudocolor map indexed at the blob number. For example,
[ind_image, cmap] = rgb2ind(TheColorImage);
labeled_image = ind_image + 1; %because first color of ind is 0
first_lab = labeled_image(7,38); %label of one place in the image
second_lab = labeled_image(11,20); %label of a different place in the image
first_color = cmap(first_lab,:); %rgb corresponding
second_color = cmap(second_lab,:); %rgb corresponding
if YourFunctionToTellIfColorsAreClose(first_color, second_color)
....
end
Because I got the blob table so I just need to compare like blob 1 is connected to blob 2 and 3 so I only compare the original rgb of blob 1 and 2 and then blob 3 and blob1.
This 2 line is label a position only~I need compare the median whole blob 1 in original image and median whole blob2 in original image.
first_lab = labeled_image(7,38); %label of one place in the image
second_lab = labeled_image(11,20); %label of a different place in the image
can I chg this to a loop so i can loop all the blob
for(x=1,x++,x<=maxblob)
first_lab=blob x
second_lab=blob x+1
first_color = cmap(first_lab,:); %rgb corresponding
second_color = cmap(second_lab,:); %rgb corresponding
end
if YourFunctionToTellIfColorsAreClose(first_color, second_color)
//compare median rgb of blob x&&blobx+1 =threshold+-5
//if first_color<= second_color threshold+-5 || first_color>=
second_color threshold+-5
//chg label blob x+1 =blob x
end
I usually is using C++ so matlab code I quite unfamiliar.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!