フィルターのクリア

How to change figure image to jpg image (image undistortion)

4 ビュー (過去 30 日間)
chee gang ngui
chee gang ngui 2022 年 5 月 25 日
回答済み: chee gang ngui 2022 年 6 月 3 日
IntrinsicMatrix = [4094.8006 0 0; 0 4081.8042 0; 1787.2784 1472.9443 1];
radialDistortion = [-0.1963 0.1539];
tangentialdistortion = [-0.0048 -0.0061];
cameraParams = cameraParameters('IntrinsicMatrix',IntrinsicMatrix,'RadialDistortion',radialDistortion, 'TangentialDistortion',tangentialdistortion);
I = imread ('C:\Users\nguic\Documents\MATLAB\rootimage\capture_2-18-05-22-17:44.jpg')% Direction to read file.
J = undistortImage(I,cameraParams);
figure; imshow(imresize(I,0.5)); # this sentence will generate figure image, so what should I change to get a jpg image?

回答 (3 件)

Jan
Jan 2022 年 5 月 25 日
img = imresize(I,0.5);
imwrite(img, 'YourImage.jpg')

Image Analyst
Image Analyst 2022 年 5 月 26 日
I would never use jpg if you ever plan on using that image for image analysis. Use PNG format. It's lossless compression, has none of the bad compression artifacts JPG images can have, and is pretty much the de facto standard these days. Anyway, you can use imwrite like Jan said.
Also, use more descriptive variable names (like you did in the first 4 lines) than I and J. Using single letter variables will soon make your code look like an alphabet soup of a program that is hard to maintain. Add comments too. That helps maintainability.
More robust code:
% Read in input image.
fullInputFileName = 'C:\Users\nguic\Documents\MATLAB\rootimage\capture_2-18-05-22-17:44.jpg'
% Check that the file actually exists.
if ~isfile(fullInputFileName)
% Exit if the image file is not found.
errorMessage = sprintf('Input file not found:\n\n%s', fullInputFileName);
uiwait(errordlg(errorMessage));
return;
end
originalRGBImage = imread(fullInputFileName)% Direction to read file.
% Repair the image by undoing the distortion.
undistortedImage = undistortImage(originalRGBImage, cameraParams);
imshow(undistortedImage, []);
drawnow; % Cause it to refresh screen immediately.
% Resize the image. Cut its size down by half in each dimension.
resizedImage = imresize(undistortedImage, 0.5);
imshow(resizedImage);
drawnow; % Cause it to refresh screen immediately.
% Construct output filename
outputFileName = strrep(fullInputFileName, ':', ''); % Get rid of colons because they are not allowed.
outputFileName = strrep(outputFileName, '.jpg', '.png'); % Replace jpg with png.
% Save the array to disk.
imwrite(resizedImage, outputFileName);
  7 件のコメント
chee gang ngui
chee gang ngui 2022 年 5 月 27 日
This is my image
Image Analyst
Image Analyst 2022 年 5 月 27 日
Actually we can't get rid of the drive letter colon so we have to get rid of the colons in your time stamps only after the third character in the filename. Try this:
% Read in input image.
folder = 'C:\Users\nguic\Documents\MATLAB\rootimage'
if ~isfolder(folder)
folder = pwd;
end
fullInputFileName = fullfile(folder, '1.jpg');
% Check that the file actually exists.
if ~isfile(fullInputFileName)
% Exit if the image file is not found.
errorMessage = sprintf('Input file not found:\n\n%s', fullInputFileName);
uiwait(errordlg(errorMessage));
return;
end
originalRGBImage = imread(fullInputFileName); % Direction to read file.
% Repair the image by undoing the distortion.
undistortedImage = undistortImage(originalRGBImage, cameraParams);
subplot(2, 1, 1);
imshow(undistortedImage, []);
drawnow; % Cause it to refresh screen immediately.
% Resize the image. Cut its size down by half in each dimension.
resizedImage = imresize(undistortedImage, 0.5);
subplot(2, 1, 2);
imshow(resizedImage);
drawnow; % Cause it to refresh screen imme
% Construct output filename
% Get rid of colons after column 3 because they are not allowed,
% and the user had some in there because the time was encoded into the file name..
strNoColons = strrep(fullInputFileName(3:end), ':', '');
outputFileName = [fullInputFileName(1:2), strNoColons];
[folder, baseFileNameNoExt, ext] = fileparts(outputFileName);
outputFileName = fullfile(folder, [baseFileNameNoExt, '.png'])
fprintf('Writing "%s".\n', outputFileName);
% Save the array to disk.
imwrite(resizedImage, outputFileName);

サインインしてコメントする。


chee gang ngui
chee gang ngui 2022 年 6 月 3 日
thank you!

カテゴリ

Help Center および File ExchangeDeep Learning for Image Processing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by