Effacer les filtres
Effacer les filtres

Grayscale and binary at the same figure with high QUALITY!

4 vues (au cours des 30 derniers jours)
Steven
Steven le 20 Déc 2013
Commenté : Image Analyst le 20 Déc 2013
Hi.
How can I put a grayscale and its binary at the same figure [(next to each other) for comparison] with HIGH RESOLUTION?
I know I can do it with subplot, but it reduces the quality and wastes a lot of space of figure size. you know what I mean? Is there another way?
What I want is for example something like imwrite (which saves all the info of the figure) but for both grayscale and binary.
I could do so for two binary images by putting an empty (or full!) matrix between them, but for a grayscale and binary, how may I do so, since their color info and type are very different.
Thanks so much!
Steven

Réponse acceptée

Image Analyst
Image Analyst le 20 Déc 2013
Stitch them together, like this:
% First need to make the binary image in the range 0-255 instead of 0-1 so you can see it.
binaryImage = 255 * uint8(binaryImage);
stitchedImage = [grayImage, binaryImage];
imshow(stitchedImage, []);
Here's a full blown demo:
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 = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, '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
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(1,2,1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Create a binary image by thresholding.
binaryImage = grayImage > 100;
subplot(1,2,2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Create a new figure window.
figure;
% Stitch them together.
% First need to make the binary image in the range 0-255 instead of 0-1 so you can see it.
binaryImage = 255 * uint8(binaryImage);
stitchedImage = [grayImage, binaryImage];
imshow(stitchedImage, []);
title('Stitched Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
  3 commentaires
Steven
Steven le 20 Déc 2013
Hi again!
Is it possible to show several images in several rows? I mean something like subplot?
Thanks!
Image Analyst
Image Analyst le 20 Déc 2013
Sure
image2x2 = [image1, image2; image3, image4];
% Use semi colon to get new row.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by