Use adjusted with imcontrast tool image

4 Ansichten (letzte 30 Tage)
DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS am 8 Dez. 2018
Beantwortet: Image Analyst am 18 Jun. 2024
I dont know how to use the image which is adjusted from imcontrast tool. I take my original photo(image1) and then i turn to gray and open the imcontrast tool.
I intend to crop the new adjusted image.How can i do it? I tried this but doesn't work
clear all;
clc;
imtool close all;
getfile = uigetfile('*.jpg','Pick an image');
image1=imread(getfile);
image2=rgb2gray(image1);
h1 = figure;
imshow(image2);
h=imcontrast(h1)
f = sprintf('Begin by choosing the desired values for contrast .\n Then select a ROI and double click to crop');
uiwait(warndlg(f));
[cropped, rect] = imcrop(h);

Antworten (2)

Sanjana
Sanjana am 18 Jun. 2024
Hi,
You can save the modified image with respect to contrast using the option "Save as" under "File" option present in "figure" window and then use "imcrop" tool to crop the ROI of the modified Image.

Image Analyst
Image Analyst am 18 Jun. 2024
Using the option "Save as" under the File menu in the figure will not save the full sized image. It basically saves a screenshot of the image. Just try it on an image that is bigger than your screen (like any image from a digital camera). You'll see the image is much smaller.
What you really need to do is to use getimage to extract the full size image from the figure. Here is a full demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fprintf('Beginning to run %s.m at %s...\n', mfilename, datetime('now','TimeZone','local','Format','HH:mm:ss'));
imtool close all;
[baseFileName, folder] = uigetfile('*.jpg','Pick an image');
fullFileName = fullfile(folder, baseFileName);
rgbImage=imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
if numberOfColorChannels == 3
grayImage = rgb2gray(rgbImage);
else
grayImage = rgbImage;
end
hFig = figure('Name', 'Original Grayscale Image');
hAxis = imshow(grayImage);
axis('on', 'image')
drawnow;
instructions = sprintf('Begin by choosing the desired values for contrast.');
uiwait(helpdlg(instructions))
hTool = imcontrast(hFig);
instructions = sprintf('Click the Adjust Data button when done, then click OK on this popup message.');
uiwait(helpdlg(instructions))
% Extract the image from the axes on the figure.
grayImage2 = getimage(hAxis);
hFig2 = figure('Name', 'Adjusted Image');
imshow(grayImage2);
drawnow;
axis('on', 'image')
% Ask user to crop image.
instructions = sprintf('Select a ROI and double click inside box to crop it.');
uiwait(helpdlg(instructions))
[croppedImage, rect] = imcrop(hFig);
% Show the cropped adjusted image.
hFig3 = figure('Name', 'Cropped, Adjusted Image');
imshow(croppedImage);
axis('on', 'image')
fprintf('Done running %s.m at %s...\n', mfilename, datetime('now','TimeZone','local','Format','HH:mm:ss'));

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by