Info
This question is closed. Reopen it to edit or answer.
Matlab multilevel array data removal based on value
1 view (last 30 days)
Show older comments
I have a 1152x1324x3 uint8 array comprised of RGB values (the interval for all values is [0,255] for each of the three levels). A sample of the data is listed below:
ans(:,:,1) =
*0* 132 132 140 140 169 169 120 120 126 126
*0 0 0 0 0* 114 114 147 147 134 134
*0 0 0 0 0* 114 114 147 147 134 134
ans(:,:,2) =
*0* 118 118 125 125 161 161 120 120 130 130
*0 0 0 0 0* 110 110 141 141 128 128
*0 0 0 0 0* 110 110 141 141 128 128
ans(:,:,3) =
*0* 94 94 100 100 137 137 73 73 82 82
*0 0 0 0 0* 79 79 86 86 71 71
*0 0 0 0 0* 79 79 86 86 71 71
I would like to scan the data and remove all entries in which the value for all three levels is 0. The entries which are bolded (have *s around them) are examples of the entries that I would like removed completely. How would I do this?
1 Comment
Image Analyst
on 17 Jun 2015
Keeping in mind that images must remain rectangular, what does "remove" mean to you? You can't have images with 10 columns in row 1 and 6 columns in rows 2 and 3. There has to be some value there. Why don't you just step back and give us the overall big picture (no pun intended). You can't "remove" pixels, but what do you really want to accomplish? Do you want to find regions of a certain color, or what????
Answers (1)
Andrew Schenk
on 18 Jun 2015
Edited: Andrew Schenk
on 18 Jun 2015
The comment by Image Analyst is correct, every pixel location in an image must have some RGB value, so you cannot remove them per se.
However, to find which (i,j) locations are 0 in all three levels, you can use the MATLAB code below. This will return a logical 1152x1324 matrix in your case with 1's in the locations where the three level values are all 0.
all(~YourMatrix, 3)
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!