Enhancing an RGB image to identify a feature
조회 수: 9 (최근 30일)
이전 댓글 표시
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/843265/image.jpeg)
Any help is appreciated, thank you!
댓글 수: 1
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(:))
whos
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
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);
댓글 수: 0
추가 답변 (1개)
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
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 Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!