필터 지우기
필터 지우기

Can anyone help me why this code gives me this error " In EnhanceMulticolorImages1 (line 41) Error using imread>parse_inputs (line 445) The file name or URL argument must be a character vector.? I need to calculate the % intensity of each color.

조회 수: 2 (최근 30일)
[filename, pathname] = uigetfile( ...
{'*.*','All Files (*.*)'}, ...
'Pick a file','C:\Users\gnya01\Desktop\Backup from L drive\DermaScope Images'); %Change Based on where you want default location
%Load image;
imname409=uigetfile('*.jpg','select jpg image',pathname);
truecolor =imread(strcat(pathname,imname409));
figure
imshow(truecolor);
title('Truecolor Composite (Un-enhanced)')
text(size(truecolor,2), size(truecolor,1) + 15,...
'Image courtesy of Space Imaging, LLC',...
'FontSize', 7, 'HorizontalAlignment', 'right');
%By viewing a histogram of the red band, for example, you can see that the data is concentrated within a small part of the available dynamic range. This is one reason why the truecolor composite appears dull.
figure
imhist(truecolor(:,:,1))
title('Histogram of the Red Band (Band 3)');
%Another reason for the dull appearance of the composite is that the visible bands are highly correlated with each other. Two- and three-band scatterplots are an excellent way to gauge the degree of correlation among spectral bands. You can make them easily just by using plot.
r = truecolor(:,:,1);
g = truecolor(:,:,2);
b = truecolor(:,:,3);
figure
plot3(r(:),g(:),b(:),'.')
grid('on')
xlabel('Red (Band 3)')
ylabel('Green (Band 2)')
zlabel('Blue (Band 1)')
title('Scatterplot of the Visible Bands');
%When you use imadjust to apply a linear contrast stretch to the truecolor composite image, the surface features are easier to recognize.
stretched_truecolor = imadjust(truecolor,stretchlim(truecolor));
figure
imshow(stretched_truecolor)
title('Truecolor Composite after Contrast Stretch');
%A histogram of the red band after applying a contrast stretch shows that the data has been spread over much more of the available dynamic range.
figure
imhist(stretched_truecolor(:,:,1))
title('Histogram of Red Band (Band 3) after Contrast Stretch');
%Another way to enhance the truecolor composite is to use a decorrelation stretch, which enhances color separation across highly correlated channels. Use decorrstretch to perform the decorrelation stretch (followed by a linear contrast stretch, as specified by the optional parameter-value pair 'Tol' and 0.1).
decorrstretched_truecolor = decorrstretch(truecolor, 'Tol', 0.4);
figure
imshow(decorrstretched_truecolor)
title('Truecolor Composite after Decorrelation Stretch');
%As expected, a scatterplot following the decorrelation stretch shows a strong decrease in correlation.
r = decorrstretched_truecolor(:,:,1);
g = decorrstretched_truecolor(:,:,2);
b = decorrstretched_truecolor(:,:,3);
figure
plot3(r(:),g(:),b(:),'.')
grid('on')
xlabel('Red (Band 3)')
ylabel('Green (Band 2)')
zlabel('Blue (Band 1)')
title('Scatterplot of the Visible Bands after Decorrelation Stretch');
% %Construct a CIR composite by reading from the original LAN file and composing an RGB image that maps bands 4, 3, and 2 to red, green, and blue, respectively.
% CIR = multibandread('paris.lan', [512, 512, 7], 'uint8=>uint8', ...
% 128, 'bil', 'ieee-le', {'Band','Direct',[4 3 2]});
% %Even though the near infrared (NIR) band (Band 4) is less correlated with the visible bands than the visible bands are with each other, a decorrelation stretch makes many features easier to see.
stretched_CIR = decorrstretch(truecolor, 'Tol', 0.1);
figure
%img1 = imshow(stretched_CIR);
%title('CIR after Decorrelation Stretch');
%A property of color infrared composites is that they look red in areas with a high vegetation (chlorophyll) density. Notice that the Bois de Boulogne park is red in the CIR composite, which is consistent with its green appearance in the decorrelation-stretched truecolor composite.
img1 = imread(stretched_CIR);
imh = imshow(img1);
% Create a mask using freehand ROI
img1 = imwrite(stretched_CIR, truecolor);
imshow(test);
h = imfreehand;
m = createMask(h, img1);
%delete(h)
% Extract individual color channels
r = img1(:,:,1);
g = img1(:,:,2);
b = img1(:,:,3);
% Get sum of intensity of each channel
r_s = sum(r(m));
g_s = sum(g(m));
b_s = sum(b(m));
% Calculate percentage of intensity of each color
r_p = r_s / (r_s + g_s + b_s) * 100;
g_p = g_s / (r_s + g_s + b_s) * 100;
b_p = b_s / (r_s + g_s + b_s) * 100;

답변 (2개)

Walter Roberson
Walter Roberson 2017년 6월 22일
You have
imname409=uigetfile('*.jpg','select jpg image',pathname);
truecolor =imread(strcat(pathname,imname409));
You should be using
[imname409, pathname2] = uigetfile('*.jpg', 'select jpg image', pathname);
if isnumeric(imname409); return; end %user cancelled
truecolor = imread( fullfile(pathname2, imname409) );
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 6월 22일
Your code has
stretched_CIR = decorrstretch(truecolor, 'Tol', 0.1);
figure
%img1 = imshow(stretched_CIR);
%title('CIR after Decorrelation Stretch');
%A property of color infrared composites is that they look red in areas with a high vegetation (chlorophyll) density. Notice that the Bois de Boulogne park is red in the CIR composite, which is consistent with its green appearance in the decorrelation-stretched truecolor composite.
img1 = imread(stretched_CIR);
We see from https://www.mathworks.com/help/images/ref/decorrstretch.html that [...] and returns the result in S. S has the same size and class as A [...]
Your array truecolor is numeric, so your result stretched_CIR is numeric. But then you try to imread() from that numeric array.
It is not clear to me why you are not just using
img1 = stretched_CIR;
Surya Gnyawali
Surya Gnyawali 2017년 6월 23일
%img1 = imread(stretched_CIR); img1 = stretched_CIR; imh = imshow(img1); % Create a mask using freehand ROI %img1 = imwrite(img1, truecolor); imshow(img1); h = imfreehand; m = createMask(h, imh); %delete(h) % Extract individual color channels r = img1(:,:,1); g = img1(:,:,2); b = img1(:,:,3); % Get sum of intensity of each channel r_s = sum(r(m)); g_s = sum(g(m)); b_s = sum(b(m)); % Calculate percentage of intensity of each color r_p = r_s / (r_s + g_s + b_s) * 100; g_p = g_s / (r_s + g_s + b_s) * 100; b_p = b_s / (r_s + g_s + b_s) * 100;

댓글을 달려면 로그인하십시오.


Surya Gnyawali
Surya Gnyawali 2017년 6월 23일
imwrite(stretched_CIR, truecolor);
why this part still give me error: img1 = imwrite(stretched_CIR, truecolor); Error using imwrite Too many output arguments.
  댓글 수: 3
Surya Gnyawali
Surya Gnyawali 2017년 6월 23일
편집: Surya Gnyawali 2017년 6월 23일
img1 = stretched_CIR; imh = imshow(img1); % Create a mask using freehand ROI img1 = imwrite(img1, truecolor); imshow(img1); h = imfreehand; m = createMask(h, imh); %delete(h) % Extract individual color channels r = img1(:,:,1); g = img1(:,:,2); b = img1(:,:,3); % Get sum of intensity of each channel r_s = sum(r(m)); g_s = sum(g(m)); b_s = sum(b(m)); % Calculate percentage of intensity of each color r_p = r_s / (r_s + g_s + b_s) * 100; g_p = g_s / (r_s + g_s + b_s) * 100; b_p = b_s / (r_s + g_s + b_s) * 100;
I want to fix this part of the code and get the intensity of each channel. Need help please
The error I got is as below after I draw freehand ROI
Error using iptcheckhandle (line 54) Function IMROI expected its second input argument, h_im, to be a valid handle to a single graphics object.
Error in imroi/parseInputsForCreateMask (line 106) iptcheckhandle(h_im,{'image'},'imroi','h_im',2)
Error in imroi/createMask (line 258) [obj,h_im] = parseInputsForCreateMask(varargin{:});
Surya Gnyawali
Surya Gnyawali 2017년 6월 23일
img1 = stretched_CIR;
This part of your help did work. The rest of it is not. Need help[. I appreciat3e your help. Can you help me how to give credit to someone like you because you are helping?

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by