How to change the pixel value of rgb unit8 image to NaN or black
古いコメントを表示
I have a rgb image, I want to change the pixel values greater than (r:175,g:255,b:55) to Nan or black . How can I do that. Please let me know Image info: I , uint8 0 255
採用された回答
その他の回答 (2 件)
Alex Taylor
2013 年 5 月 22 日
0 投票
I think we would need some clarifying information to answer this question.
What does it mean to have a pixel value "greater" than (175,255,55)? If any one of the three channels is greater than your cutoff, do you want to clip to black? If all three channels are greater than your cutoff, do you want to clip to black?
Also, integer types do not define NaN, so you are going to need to use an integral value to represent black (e.g. 0).
Have you considered converting your image to grayscale before thresholding the intensity values? Have you considered thresholding in a different colorspace (working on the L channel in LAB space) then converting back?
Image Analyst
2013 年 5 月 22 日
0 投票
Alex is right. We need the big picture here. WHY do you think you need to do that? What do you really want to do? It's possible that setting pixels to nan or black is not really the best approach to what you want to accomplish. So please share what you want to accomplish instead of focusing on what you think may be the best approach. Do you want to measure something (e.g. area, shape, or mean color) of objects of a particular color, or something else? You can upload your picture to http://snag.gy and tell us what you want to do or measure in your picture.
9 件のコメント
Ankit Gupta
2013 年 5 月 22 日
編集済み: Image Analyst
2013 年 5 月 22 日
Image Analyst
2013 年 5 月 22 日
Well certainly you can at least focus the lens.
Ankit Gupta
2013 年 5 月 22 日
編集済み: Ankit Gupta
2013 年 5 月 22 日
Image Analyst
2013 年 5 月 22 日
Then buy a better camera. You'll spend more in time trying to fix the focus problem that if you just bought a camera with a lens you can focus.
Ankit Gupta
2013 年 5 月 22 日
編集済み: Ankit Gupta
2013 年 5 月 22 日
Alex Taylor
2013 年 5 月 22 日
You cannot put a NaN in any image whose datatype is uint8. The value NaN is not defined in integer datatypes, only floating point datatypes (e.g. double, single).
One way to think about this is the following piece of code in which I attempt to cast the value NaN to uint8 in MATLAB:
uint8(NaN)
In MATLAB, we cast NaN to 0 when casting to integer types by convention (because NaN isn't defined in uint8).
Ankit Gupta
2013 年 5 月 22 日
Image Analyst
2013 年 5 月 22 日
I'm 99% certain you don't need to convert anything to nan or black. What do you think you'd do if that were done?
Ankit Gupta
2013 年 5 月 22 日
編集済み: Ankit Gupta
2013 年 5 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Image Preview and Device Configuration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

