How do I obtain all rgb pixels from an image instead of just one pixel from user input? And then how do I output that data to a csv file?
4 views (last 30 days)
Show older comments
Heres the code
function pushbutton2_Callback(hObject, eventdata, handles)
global R G B range img unit
[col,row] = ginput(1); % Get point position from user
col = fix(col); row = fix(row);
% Create temperature as function in RGB
T = linspace(range(1),range(2),length(R)); T = T';
r = img(row,col,1); % Red component of selected point
g = img(row,col,2); % Green component of selected point
b = img(row,col,3); % Blue component of selected point
%Looking for the closest point on the colormap
for tol = 1:length(R);
idx=((R<r+tol)&(R>r-tol))&((G<g+tol)&(G>g-tol))&((B<b+tol)&(B>b-tol));
t = T(idx);
if ~isempty(t),break,end
end
In trying to change [col,row] = ginput(1) so that it gets all the rgb values and puts them into the temperature equation to then be displayed on a csv file.
0 Comments
Answers (1)
Image Analyst
on 12 Aug 2022
You seem to already have a variable called img. That IS all the pixel values for all locations. If you want just one row, column you can use impixel or do it like you did.
If you want a CSV file, see my attached demo.
2 Comments
Image Analyst
on 12 Aug 2022
Perhaps
[r, g, b] = imsplit(rgbImage);
mask = ((R<r+tol)&(R>r-tol))&((G<g+tol)&(G>g-tol))&((B<b+tol)&(B>b-tol));
Just operate on the whole images if you want the temperature of the whole image. Don't use ginput() and a for loop. I'm not sure what your temperature equation is.
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!