error zoom image matlab

5 visualizaciones (últimos 30 días)
linou landini
linou landini el 29 de Oct. de 2021
Comentada: Image Analyst el 8 de Nov. de 2021
img = imread('image.png')
resultat= img(1:100,1:200)
imshow(resultat)
  19 comentarios
DGM
DGM el 30 de Oct. de 2021
Editada: DGM el 30 de Oct. de 2021
A = imread('peppers.png');
B = rgb2gray(A);
imshow(B)
size(A)
ans = 1×3
384 512 3
size(B)
ans = 1×2
384 512
linou landini
linou landini el 30 de Oct. de 2021
@DGM thanks

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 29 de Oct. de 2021
@linou landini you are getting the actual image. It is not blurrier than your original image. It is exactly what it looks like. If you displayed the cropped/extracted image on the same scale as the original image from where it came, they would look identical. If it looks blurry, then it was also blurry in the original image.
See truesize() function, and the attached demo.
To colorize a gray scale image, one way is to use ind2rgb() with the colormap of your choice.
  2 comentarios
linou landini
linou landini el 29 de Oct. de 2021
plz @Image Analyst can you open this zomm_image.m and send me the code . thank you
Image Analyst
Image Analyst el 29 de Oct. de 2021
@linou landini, you can just right click on it and save it. Anyway, here it is:
% Demo of how to zoom and pan/scroll the image using a imscrollpanel control.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
% IMSHOW has historically had this behavior all the way back to 1993, that is, it shows the whole image.
% If it can show the whole image at “truesize” or more recently called 100, it does,
% but if not, it shows the whole image.
% We introduced IMTOOL and IMSCROLLPANEL, and now there’s more flexibility with the display
% because the scroll panel shows you that there is more image there beyond what you can see.
% Have you tried using IMSCROLLPANEL in combination with IMSHOW? See example below or in:
% doc imscrollpanel
%
% It allows you to directly set the magnification, programmatically or through a magnification box.
% When we created IMSCROLLPANEL and the associated magnification controls in IPT5,
% we hoped that they would satisfy exactly this GUI use case.
%
% Let me know what you think if you try it, or if you've tried it in the past, why it doesn't meet your needs.
% We're open to discussing this further with you to see if we can fix the issue or make the better solution easier to discover if it's indeed adequate.
% Jeff Mather - Image Processing Toolbox developer team leader.
% Here's the example from the documentation:
% Create a scroll panel with a Magnification Box and an Overview tool.
hFig = figure('Toolbar', 'none',...
'Menubar', 'none');
hIm = imshow('saturn.png');
hSP = imscrollpanel(hFig,hIm); % Handle to scroll panel.
set(hSP,'Units', 'normalized',...
'Position', [0, .1, 1, .9])
% Add a Magnification Box and an Overview tool.
hMagBox = immagbox(hFig, hIm);
boxPosition = get(hMagBox, 'Position');
set(hMagBox,'Position', [0, 0, boxPosition(3), boxPosition(4)])
imoverview(hIm)
% Get the scroll panel API to programmatically control the view.
api = iptgetapi(hSP);
% Get the current magnification and position.
mag = api.getMagnification();
r = api.getVisibleImageRect();
% Demonstrate scrolling.
% View the top left corner of the image.
message = sprintf('Click OK to view the top left corner of the image');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setVisibleLocation(0.5,0.5)
% Change the magnification to the value that just fits.
message = sprintf('Click OK to change the magnification to the value that just fits');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnification(api.findFitMag())
% Zoom in to 1600% on the dark spot.
message = sprintf('Click OK to zoom in to 1600%% on the dark spot.');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnificationAndCenter(16,306,800)
% Zoom in to 100% with upper left showing.
message = sprintf('Click OK to zoom in to exactly 100%%.');
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Quit')
return;
end
api.setMagnificationAndCenter(1,1,100)

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 30 de Oct. de 2021
we're (or at least I'm) not sure what you want. Initially you talk about resizing and spatial resolution. Then in this comment, you ask about colorizing a (possibly) gray scale image to be full, true RGB color.
Then in this comment you ask about the converse - converting a true color RGB image into gray scale.
Maybe you want all three - I don't know. But it seems like you should have all three now.
One additional thing you may get around to asking is how to transfer the colors of one RGB image to another RGB image. For that, the best I have seen is this:
  15 comentarios
Walter Roberson
Walter Roberson el 7 de Nov. de 2021
linou landini
linou landini el 8 de Nov. de 2021
@Walter Roberson thank you very much it's what I want. plz @DGM if you did not understand please do not answer!!

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 8 de Nov. de 2021
Actually I agree with @DGM and I know now that you don't want me to answer but I thought I'd make one last attempt to help you. So now from your comment to Walter, and your listed wants:
  1. Extract a rectangular ROI "resultat" from the image
  2. make 3687 patches, but for each I want to calculate the axes of each patch
  3. transfer color gamut from one photo to another
  4. colorize pixels that are different between two images.
it appears that you want #4. So here is code to do that:
% Demo by Image Analyst.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
%-----------------------------------------------------------------------------------------------------------------------------------
% Read in image.
folder = [];
baseFileName = 'peppers.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display the image.
subplot(3, 1, 1);
imshow(rgbImage, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
caption = sprintf('Original RGB Image : "%s"\n%d rows by %d columns', baseFileName, rows, columns);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
hFig1 = gcf;
hFig1.Units = 'Normalized';
hFig1.WindowState = 'maximized';
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
hFig1.Name = 'Demo by Image Analyst';
%-----------------------------------------------------------------------------------------------------------------------------------
% Add noise to get some differences
noisy = imnoise(rgbImage, "gaussian", 0, .020);
% Display the image.
subplot(3, 1, 2);
imshow(noisy, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
title('Noisy RGB Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Find differences
mask = imabsdiff(rgbImage, noisy);
% Display the image.
subplot(3, 1, 3);
imshow(mask, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
title('Difference Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
msgbox('Done!');
Adapt as needed.
  1 comentario
Image Analyst
Image Analyst el 8 de Nov. de 2021
Not sure what your edit to your original post was.
Does this code do what you were looking for.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by