img = imread('image.png')
resultat= img(1:100,1:200)
imshow(resultat)

댓글 수: 19

DGM
DGM 2021년 10월 29일
편집: DGM 2021년 10월 29일
You cropped out a 100x200px piece of the image. That's all the information there is. If you scale up a tiny piece of an image, you get a bigger image with the same amount of information as the tiny piece. It will be blocky due to the fact that imshow() does nearest-neighbor interpolation when scaling.
img = imread('cameraman.tif');
resultat = img(51:80,101:130);
imshow(resultat)
What exactly are you intending to do?
linou landini
linou landini 2021년 10월 29일
편집: linou landini 2021년 10월 29일
hi @DGM I have a large size image, and I will retrieve part of the image (200,200) to classify it.
But the result is blurry.
Walter Roberson
Walter Roberson 2021년 10월 29일
imshow() defaults to resizing the figure and axes to present the software pixels 1:1 to hardware pixels (I do not know how the virtual scaling for high resolution displays affects that)
linou landini
linou landini 2021년 10월 29일
편집: linou landini 2021년 10월 29일
@Walter Roberson so how do I get part of the image? and how I do the coloring of this image
The blurred image DGM shows is an artifact of this MATLAB Answers "Run" facility. If you run the same code at the MATLAB command line, you will get only a small image, roughly 3/4 cm wide on my monitor.
The 3/4 or so cm wide display is the faction of the image.
You would color it however was appropriate for your algorithm.
img = imread('cameraman.tif');
resultat = img(51:80,101:130);
image(resultat)
colormap(hsv)
axis image
set(gca, 'units', 'pixels')
pos = get(gca, 'Position');
set(gca, 'Position', [pos(1), pos(2), 30, 30])
linou landini
linou landini 2021년 10월 29일
@Walter Roberson what does mean les différents couleurs? and two parties of images contenuous the same coulor ?
In what I posted just above, the colors do not have any inherent meaning.
img = imread('cameraman.tif');
resultat = img(51:80,101:130);
imshow(resultat)
colormap(hsv(256))
colorbar
imshow(resultat)
colormap(jet(256))
colorbar
imshow(resultat)
colormap(flag(256))
colorbar
Same image, three different color maps.
In this particular way of displaying data, the uint8 values in resultat have 1 added (so become 1 to 256 instead of 0 to 255), and the result is used to index into rows of the 256 entry colormap such as jet(256), and the resulting row of RGB values is used for the pixel. The correspondance between value and color does not have to mean anything. Two pixels the same color might mean that the pixels had the same value -- but as you can see from that last flag example, it might just mean that the color map happened to have the same color for multiple entries.
linou landini
linou landini 2021년 10월 29일
@Walter Roberson thanks, just question .
when I color two images which are acquired at two different times, when I color the first and the second and I differentiate the two images. The pixel value does the same color in the both images when they are equals?
cim1 = imresize(imread('peppers.png'), [128 128]);
cim2 = imresize(imread('flamingos.jpg'), [128 128]);
gim1 = rgb2gray(cim1);
gim2 = rgb2gray(cim2);
cmap = jet(256);
imshow(gim1); colormap(cmap)
imshow(gim2); colormap(cmap)
So now we have two grayscale images that we have displayed in pseudo-color.
If we have two pixels that are the same in the two recolored images, then does it mean that the two original color images were the same? Let us pick out the first pixel and check:
gim1(1,1)
ans = uint8 44
[r1, c1] = find(gim2 == gim1(1,1), 1);
disp([r1, c1, gim2(r1, c1)])
19 2 44
So the grayscale intensity of the upper left corner of the first grayscale image is uint8(44), and that same intensity is found at row 19 column 2 of the second grayscale image.
squeeze(cim1(1,1,:)).'
ans = 1×3
63 31 62
squeeze(cim2(r1,c1,:)).'
ans = 1×3
57 39 34
So the upper left corner of the grayscale image for peppers was originally RGB [63 31 62], and row 19 column 2 of flamingos, which has exactly the same grayscale value of 44, was originally RGB [57, 39, 34], which is a different color.
Therefore, if two REcolored images have the same color for a pixel, it does not mean that the original images had the same color.
DGM
DGM 2021년 10월 30일
"If you run the same code at the MATLAB command line, you will get only a small image"
FWIW, that depends on if the figure is docked. That behavior is set in the IPT preferences panel, and the default would be as you describe ('adaptive'). If the figure is docked (or had previously been docked) when drawn to, the preferences will be ignored and the behavior will be 'fit'. I normally use docked figures, so that's the behavior I expect.
linou landini
linou landini 2021년 10월 30일
편집: linou landini 2021년 10월 30일
@Walter Roberson@DGM @Image Analyst thanks for your reply. But, when i have an image of size 900 * 900 when i transform it to size 200 * 200 do i get data?
@linou landini you will certainly get data as long as you assign the results of your cropping or resizing operation to a variable. Like:
output = squeeze(cim2(r1,c1,:)).' % Assign to output.
Walter just assumed you would know that the squeeze() results should be assigned to a variable. Did you do that? You forgot to show us how you did your "transform".
linou landini
linou landini 2021년 10월 30일
편집: linou landini 2021년 10월 30일
I just resized the image without matlab,
plz @Image Analyst how i color the first image like the second image?
and how I transform .mat to .jpg in matlab?
Let me guess, you're doing something like this:
A = imread('peppers.png');
B = A(150:200,200:250);
imshow(B)
When you should be doing
C = A(150:200,200:250,:);
clf; imshow(C)
linou landini
linou landini 2021년 10월 30일
@DGM we can resize for the .mat file without losing data?
DGM
DGM 2021년 10월 30일
Is the right image supposed to be color? Was it color before you cropped it? If you're trying to colorize an old monochrome visible photo to match the color characteristics of a newer color photo, is there any reason to assume that the meaningfulness of any subsequent comparison won't be influenced?
linou landini
linou landini 2021년 10월 30일
편집: linou landini 2021년 10월 30일
@DGM I solved my problem thanks, but I want to transmit 900 * 900 * 3 uint8 to 900 * 900 uint8
DGM
DGM 2021년 10월 30일
편집: DGM 2021년 10월 30일
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 2021년 10월 30일
@DGM thanks

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

답변 (3개)

Image Analyst
Image Analyst 2021년 10월 29일

0 개 추천

@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

linou landini
linou landini 2021년 10월 29일
plz @Image Analyst can you open this zomm_image.m and send me the code . thank you
@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)

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

Image Analyst
Image Analyst 2021년 10월 30일

0 개 추천

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

Image Analyst
Image Analyst 2021년 10월 31일
@linou landini The paper is on the web site. Code it up. I have not coded it up. Or else ask the author for it. His email address is there.
DGM
DGM 2021년 10월 31일
편집: DGM 2021년 10월 31일
As I have a feeling that the subtleties aren't important anymore, there are less ideal tools on the File Exchange that might be forced into such a role.
Considering the first two:
A = imread('sources/castle1.jpg');
B = imread('sources/castle2.jpg');
% IPT imhistmatch() (same as matchHistograms() on FEX)
C = imhistmatch(A,B);
D = imhistmatch(B,A);
% MIMT imrecolor()
E = imrecolor(B,A,'colormodel','rgby');
F = imrecolor(A,B,'colormodel','rgby');
G = imrecolor(B,A,'colormodel','lch');
H = imrecolor(A,B,'colormodel','lch');
labels = {textim('imrecolor() LCHuv','ibm-iso-16x9'); ...
textim('imrecolor() RGB','ibm-iso-16x9'); ...
textim('imhistmatch()','ibm-iso-16x9'); ...
textim('ORIGINALS','ibm-iso-16x9')};
labels = imstacker(labels,'size',[size(labels{1},1) size(A,1)], ...
'padding',0,'dim',4);
labels = repmat(rot90(reshape(labels,size(labels,1),[],1,1)),[1 1 3]);
comp = [im2uint8(labels) [A B; C D; E F; G H]];
Obviously, the results are nowhere near as good as those from the above paper. I don't know about matchHistograms(), but I never really intended imrecolor() to be used on photographic content. It was quite literally intended to content-abusive.
matchHistograms() (File Exchange) does the same thing that imhistmatch() (IPT) does. It takes the histogram of the reference image and applies it to the working image using histeq() operating in RGB. The histogram matching isn't ever very good, and working in RGB pretty much dooms the apparent quality of the result anyway.
imrecolor() (File Exchange) works in any one of several available color models. It simply does brightness binning on both images and then does histogram matching of color (hue, saturation/chroma) components within each bin. The result is a brightness-correlated color distribution match. It's a marginal improvement over imhistmatch() for operations in RGB, but nothing about it guarantees the process to be continuous or monotonic as in the paper that IA linked (hence the banding).
DGM
DGM 2021년 10월 31일
A mat file is a container that can hold any number of things. Unless you attach a copy of the specific file, I can only guess what's in it.
linou landini
linou landini 2021년 10월 31일
@DGM how to zoom of file.mat in 200*200 to 100*100?
DGM
DGM 2021년 10월 31일
편집: DGM 2021년 10월 31일
If it's valid image data, use imresize() or imcrop(). If you want to write it, use imwrite().
I do not understand the question about calculating (xa, ya) "for each patches 3687" ?
If you want to find 3687 different patches in the image, then go ahead and do that.
If you have a fixed patch size, and you need to generate 3687 random patch locations inside the image, then
xa = randi([1 size(TheImage,2)-PatchColumns+1], 3687, 1);
ya = randi([1 size(TheImage,1)-PatchRows+1], 3687, 1);
Walter Roberson
Walter Roberson 2021년 11월 1일
I do not know what you mean by the "axes" of each patch ?
What information do you have about the patches you made? Did you keep a record of their locations?
Or are you given patches and the problem is to locate (as close as possible) to the patch within the original image, going by matching the pixels ?
linou landini
linou landini 2021년 11월 7일
편집: Walter Roberson 2021년 11월 7일
@Walter Roberson @DGM @Image Analyst who color the pixels in images ?
for(i=1;i:200)
for(j=1:200)
if (m(i,j) ~=t(i,j))
color(m(i,j))
end
end
end
Walter Roberson
Walter Roberson 2021년 11월 7일
I don't think I understand the question about who color the pixels in images?
Image Analyst
Image Analyst 2021년 11월 7일
@linou landini I guess it would be you, or a function you call. Essentially you create your colors then I guess you're going to apply the color either by burning it into the image, or showing it above the image in an overlay (which may or may not have some transparency). Please give the current version of your code, not just this small snippet from it.
linou landini
linou landini 2021년 11월 7일
편집: linou landini 2021년 11월 7일
@Image Analyst yes that my code @Walter Roberson I want to color the pixels that are different in image 1 and image 2
What? This:
img = imread('image.png')
resultat= img(1:100,1:200)
imshow(resultat)
or this:
for(i=1;i:200)
for(j=1:200)
if (m(i,j) ~=t(i,j))
color(m(i,j))
end
end
end
or something else? Either way, you're not really doing anything and worse, we don't know what you want to do. So we don't know how to help you.
DGM
DGM 2021년 11월 7일
편집: DGM 2021년 11월 7일
@linou landini This thread has been going on for over a week, and you haven't provided a clear or consistent description of your task or any substantial example of your working code.
When you ask a question, read your question and ask yourself if you have communicated enough information to constitute an answerable question. It's understandable if you're not sure, but be prepared and willing to provide clarification as needed.
If no clarification is provided and the form of the question keeps changing, you'll get a collage of guesses that describes little more than the extent of patience. It's not a good way to get help.
linou landini
linou landini 2021년 11월 8일
@Walter Roberson thank you very much it's what I want. plz @DGM if you did not understand please do not answer!!

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

Image Analyst
Image Analyst 2021년 11월 8일

0 개 추천

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

Image Analyst
Image Analyst 2021년 11월 8일
Not sure what your edit to your original post was.
Does this code do what you were looking for.

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

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2021년 10월 29일

댓글:

2021년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by