Enhancing an RGB image to identify a feature
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Manas Pratap
am 24 Dez. 2021
Beantwortet: yanqi liu
am 27 Dez. 2021
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 Kommentar
Walter Roberson
am 25 Dez. 2021
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.
Akzeptierte Antwort
yanqi liu
am 27 Dez. 2021
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 Kommentare
Weitere Antworten (1)
Image Analyst
am 24 Dez. 2021
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 Kommentare
Image Analyst
am 26 Dez. 2021
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.
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










