Enhancing an RGB image to identify a feature

9 ビュー (過去 30 日間)
Manas Pratap
Manas Pratap 2021 年 12 月 24 日
回答済み: yanqi liu 2021 年 12 月 27 日
I have an image which has a faint line that is NOT continuous. I want to find the pixel intensities along the line so that if there is a drop in intensity i can identify it as a break in the line. For example, in the green apparently "uniform" line below, there are supposed to breaks in between. I need to find the pixel intensities along that line to find the break. I tried using the image tool to see the pixel intensities, however, the breaks are too faint to be noticed.
I tried enhancing the image by using imadjust (both in rgb and converting to grayscale then trying imadjust) but it didnt help. Any other methods to enhance the line so that the breaks are visible, or atleast the pixel intensity variations along the line are significant?
Any help is appreciated, thank you!
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 12 月 25 日
You might be able to work something along these lines
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/843265/image.jpeg';
img = imread(filename);
imshow(img)
imshow(img(:,:,1)); title('r');
imshow(img(:,:,2)); title('g');
imshow(img(:,:,3)); title('b');
lab = rgb2lab(img);
min(lab(:)),max(lab(:))
ans = -20.3143
ans = 91.8858
whos
Name Size Bytes Class Attributes ans 1x1 8 double filename 1x80 160 char img 274x767x3 630474 uint8 lab 274x767x3 5043792 double
imshow(lab(:,:,1), []); title('L');
imshow(lab(:,:,2), []); title('a');
imshow(lab(:,:,3), []); title('b');
Notice that 'a' appears to distinguish the line we want in a way that hints we might be able to binarize. But at what values?
imagesc(lab(:,:,2)); colormap(parula); colorbar(); title('a colorizeed');
abin = lab(:,:,2) > 0 & lab(:,:,2) < 14;
imshow(abin); title('a bin')
If you change to < 15 instead of < 14 then a lot more shows up in white, and you can see the line doesn't show up long enough, so somehow the hints from the imshow(, []) do not carry over well to the imagesc(); colormap('parula'). Perhaps using the data cursor on the imshow(lab(:,:,2),[]) would help find a range of values that is more usable.

サインインしてコメントする。

採用された回答

yanqi liu
yanqi liu 2021 年 12 月 27 日
clc; clear all;
close all;
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/843265/image.jpeg');
J = rgb2ycbcr(img);
im = mat2gray(J(:,:,1));
im = imadjust(im, [0.45 0.8], [0 1]);
ed = imbinarize(im,'adaptive','ForegroundPolarity','dark','Sensitivity',0.65);
ed2 = imclose(imopen(ed, strel('line', 11, 0)), strel('line',19,0));
ed2 = bwareafilt(imclearborder(ed2), 1);
[r, c] = find(ed2);
p = polyfit(c,r,3);
x = linspace(1,size(im,2),2e2);
y = polyval(p, x);
figure;
subplot(2, 2, 1); imshow(img);
subplot(2, 2, 2); imshow(im, []);
subplot(2, 2, 3); imshow(ed, []);
subplot(2, 2, 4); imshow(ed2, []);
hold on; plot(x,y,'r-', 'LineWidth', 2);
% find the pixel intensities along the line
g = rgb2gray(img);
g2 = zeros(size(g));
for i = 1 : length(x)
ri = round(y(i)); ci = round(x(i));
ri = min(size(g,1), max(1,ri));
ci = min(size(g,2), max(1,ci));
g2(ri,ci) = 1;
end
gs = g(logical(g2));
figure; plot(gs);

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 12 月 24 日
Did you try calling improfile(). Have the user draw a line, extract the colors along the line in each color channel, and then plot them.
  4 件のコメント
Manas Pratap
Manas Pratap 2021 年 12 月 26 日
The mostly horizontal line. It is a handheld phone snapshot,but the paper on which the line is on is suspended in a gel matrix, so adjusting the angle might not be viable.
The idea is to use something in the visible spectrum itself, perhaps changing the background light might help.
I havent tried the functions you've mentioned, but I will give them a go.
unfortunately I cannot do anything to improve the image provided to me, as it was just given to me.
Thanks for your help!
Image Analyst
Image Analyst 2021 年 12 月 26 日
Then if your image capture person can't (or is unwilling to) do anything to help you solve their problem, I suggest you give them a human-assisted solution like I originally suggested. Have them hand draw the line and then you can do whatever you want with those coordinates.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by