How can I get the histeq function to ignore NaN values?
7 ビュー (過去 30 日間)
古いコメントを表示
I have a set of 2D pictures, I want to only focus on a small blob in the middle while ignoring a sea of NaNs around it
If I keep the NaNs, histeq spits out a plain white image. Is there a way to stop NaNs from corrupting the histeq function?
thanks in advance
- Nadeem
0 件のコメント
回答 (2 件)
Ramnarayan Krishnamurthy
2017 年 9 月 22 日
It appears that MATLAB warns you about using histeq on a matrix with NaNs and replaces them to 0.
I would suggest the following if you want to apply histeq only to non-NaN values in a matrix
% Setting up a sample image
% Use im2double as double saves NaN while uint8 converts it to 0
I = im2double(imread('cameraman.tif'));
I(1:100,1:100) = NaN
I(1:256,1:100) = NaN
I(1:256,180:end) = NaN
I(1:100,:) = NaN
I(160:end,:) = NaN
figure, imshow(I)
% Duplicate Matrix
I2 = I;
% Store the output of the contrasted stretched image in I2
I2(~isnan(I2)) = histeq(I2(~isnan(I2)));
figure, imshow(I2)
Hope this helps!
0 件のコメント
Image Analyst
2017 年 9 月 22 日
I wouldn't even use histeq(). I mean, WHY? It often/usually gives crummy, harsh, unnatural looking images, and it's not needed to do image analysis.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Filtering and Enhancement についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!