Enhancing an RGB image to identify a feature

3 vues (au cours des 30 derniers jours)
Manas Pratap
Manas Pratap le 24 Déc 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 commentaire
Walter Roberson
Walter Roberson le 25 Déc 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(:))
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.

Connectez-vous pour commenter.

Réponse acceptée

yanqi liu
yanqi liu le 27 Déc 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);

Plus de réponses (1)

Image Analyst
Image Analyst le 24 Déc 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 commentaires
Manas Pratap
Manas Pratap le 26 Déc 2021
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 le 26 Déc 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by