- Are your images color or gray scale?
- What do you mean by frames (in your comment below)? Are they different images that are part of a video sequence?
- What do you mean by unique? Do you mean pixels that are the only ones to have that particular gray level or color?
- What do you mean by "extract"? Do you want the "unique" color or gray level values put into a numerical array? Like if there are 100 unique pixels you want a 100-by-3 array or a 100-by-1 array? Or, do you want a binary image that indicates where the unique pixels are located? OR, do you want a masked image where the unique pixels are their original color or gray level, and the rest of the image is blackened?
- What is the "use case"? Why do you want to do this thing? What will you do once you have what the unique pixels? This will help us figure out what you really need.
how to extract unique pixels from on image?
8 views (last 30 days)
Show older comments
how to extract unique pixels from on image? can any one share algorithm?
2 Comments
Image Analyst
on 9 Jan 2019
Accepted Answer
Stephen23
on 7 Jan 2019
>> I = randi(7,5,4,3) % MxNx3 image array.
I(:,:,1) =
3 2 5 5
7 3 6 3
6 7 6 4
5 6 4 5
1 1 1 6
I(:,:,2) =
7 2 5 2
7 4 5 7
2 2 1 4
3 7 7 2
6 3 7 7
I(:,:,3) =
1 2 2 1
7 2 6 1
5 6 4 7
7 6 5 7
4 6 3 3
>> U = unique(reshape(permute(I,[3,2,1]),3,[]).','rows') % unique pixels (each row = 1 pixel rgb)
U =
1 3 6
1 6 4
1 7 3
2 2 2
3 4 2
3 7 1
4 4 7
4 7 5
5 2 1
5 2 7
5 3 7
5 5 2
6 1 4
6 2 5
6 5 6
6 7 3
6 7 6
7 2 6
7 7 7
2 Comments
Walter Roberson
on 10 Jan 2019
Stephen's code will find the pixels that are unique over all 200 frames. It does not try to find the pixels that are unique within each frame.
I am not clear which of the two you would prefer. (Unique over the entire 200 frames is easier to process.)
More Answers (2)
Walter Roberson
on 10 Jan 2019
YourArray = imag; %using imag as a variable name is confusing because of imag() function
unique_vals = unique(YourArray(:));
num_unique = length(unique_vals);
outmap = cell(num_unique, 1);
for K = 1 : num_unique
outmap{K} = YourArray == unique_vals(K);
end
Now outmap will be a cell array with as many entries as there are values that are unique over the the entire array. Each entry in outmap will be a 1024 x 1024 x 200 array of logical, that is false in most places but true in every place that contained the correspoding unique value.
3 Comments
Walter Roberson
on 10 Jan 2019
Is the separation by grayscale intensity ? For example, perhaps intensities 40 to 73 would be one object ? If so then is there ever any overlap of intensities? Are the intensity groups known ahead of times? Is this an intensity clustering task with 6 clusters, one cluster for each of the 5 objects and a 6th cluster for the background ?
Is the separation by distance from each other in the images? For example, two cars driving on a road and you want to follow each of the cars?
If the separation is by dstance in the images, then is this an object tracking problem? For example, 5 balls bouncing, and you want to track each one, and they might overlap in some of the frames but not other frames?
KSSV
on 7 Jan 2019
Read about unique
I = imread(image) ;
R = I(:,:,1) ;
G = I(:,:,2) ;
B = I(:,:,3) ;
Ri = unique(R(:)) ;
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!