Shaila parvin asked . 2024-01-17

Is it possible to retrieve similar images by using this code?

This is a code for calculating histogram error of a selected image to all images of a folder. I want to retrieve images which are similar to the selected image. Like: all the tree images of the folder, or bird images, or people images.

 

 clc;    % Clear the command window.
 close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.
fontSize = 25;
format long g;

 % Read in a standard MATLAB gray scale demo image.
%folder = fullfile(matlabroot, '\toolbox\images\imdemos\new');
folder = fullfile('E:\4-2\Thesis_codes\similar');
baseFileName = 't5.jpg';
% 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.
  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
referenceGrayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(referenceGrayImage);
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.
  referenceGrayImage = referenceGrayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
%subplot(2, 2, 1);
%imshow(referenceGrayImage, []);
%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')

 % Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(referenceGrayImage);
%subplot(2, 2, 2);
%bar(grayLevels, pixelCount);
%grid on;
%title('Histogram of original image', 'FontSize', fontSize);
%xlim([0 grayLevels(end)]); % Scale x axis manually.

 srcFiles = dir(fullfile(folder, '*.jpg')); %directory of the source folder
Im1 = im2double(referenceGrayImage); % Calculate the Normalized Histogram
hn1 = imhist(referenceGrayImage)./numel(referenceGrayImage);

 for i = 1 : length(srcFiles)      % determins how many images are there in the folder,
  filename = fullfile(folder,srcFiles(i).name)
  thisImage = imread(filename);
  % Display the original gray scale image.
  %subplot(2, 2, 3);
  %imshow(thisImage);
  %title(filename, 'FontSize', fontSize);
  %drawnow;
  Im2=rgb2gray(thisImage);
  Im2 = im2double(Im2);
  hn2 = imhist(Im2)./numel(Im2);
  
  % Calculate the histogram error
  f(i) = sum((hn1 - hn2).^2);% Calculate the histogram error
    f(i) %display the result to consol
    %image=imread(fullfile(folder,srcFiles(i).name));
    %figure, imshow(image);title ('The image you have selected is an image of jute');
  if((f(i)>=0.009)&&(f(i) <=0.3))
        f(i) %display the result to consol
        image=imread(fullfile(folder,srcFiles(i).name));
        figure, imshow(image);
        %promptMessage =sprintf('f=%f',f(i));
    end
end

 

image processing , histogram , cbir , Image Processing Toolbox

Expert Answer

John Williams answered . 2024-05-03 03:57:32

No, there is a lot more to CBIR than similarity of histograms. Imagine you had an image of a bird and you took the pixels and rearranged them. Let's say that you sorted them and rearranged them into a ramp or gradient from one color to another. It would look like a smooth image - nothing at all like the original image of a bird - yet it would have the very same histogram of the bird image. Your code would return that image as being similar to a bird. That is probably not what you'd want. CBIR is a complicated and rapdily evolving subject that tags each image in the database with lots of information. You should do a search on CBIR to learn about this subject. You'll see that there's no way it can be done with a short, 100-line long MATLAB script.

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.