How to visualize LabelMe database using Matlab - database

The LabelMe database can be downloaded from http://www.cs.toronto.edu/~norouzi/research/mlh/data/LabelMe_gist.mat
However, there is another link http://labelme.csail.mit.edu/Release3.0/
The webpage has a toolbox but I could not find any database to download. So, I was wondering if I could use the LabelMe_gist.mat which has the following fields. The field names contins the labels for the images, and img perhaps contains the images. How do I display the training and test images? I tried
im = imread(img)
Error using imread>parse_inputs (line 486)
The filename or url argument must be a string.
Error in imread (line 336)
[filename, fmt_s, extraArgs, msg] = parse_inputs(varargin{:});
but surely this is not the way. Please help
load LabelMe_gist.mat;
load('LabelMe_gist.mat', 'img')

Since we had no idea from your post what kind of data this is I went ahead and downloaded it. Turns out, img is a collection of 22019 images that are of size 32x32 (RGB). This is why img is a 32 x 32 x 3 x 22019 variable. Therefore, the i-th image is accessible via imshow(img(:,:,:,i));
Here is an animation of all of them (press Ctrl+C to interrupt):
for iImage = 1:size(img,4)
figure(1);clf;
imshow(img(:,:,:,iImage));
drawnow;
end

Related

react-spring Error: <path> attribute d: Expected number

I am using React-spring to morph my svgs - in this case, rather than a true morph, I'm really just translating particular parts of a large and complex svg on the y axis. I have a button that swaps the related vectors when clicked, so part of the image moves up on the first click, and back on the second.
When I first load the svg, I don't have any errors. I start to get errors after the first click, and the errors are related to this set of vectors:
"M0 834.5L31.6776 810.203L22.1257 798.768L36.2022 791.807H53.2951L79.9399 755.511V747.059L89.9945 740.098H107.087L121.164 713.249L136.749 700.819L158.366 690.875V679.44L179.481 668.501L195.066 637.178L208.137 619.279V586.961V570.056V559.118L195.066 546.688L179.481 516.359L219.197 519.839H244.836V475.588H266.956H297.623L306.169 391.562H323.262V342.339V338.859H324.268V342.339H327.284V339.853L329.295 338.859L331.306 339.853V342.339H334.825V339.853L336.836 338.859L338.847 339.853V342.339H342.869V339.853L344.88 338.859L346.891 339.853V342.339H349.907L357.448 278.2L349.907 260.798V248.866L372.53 236.933L392.639 248.866V260.798L386.607 278.2L392.639 309.027H396.158V306.541L398.169 305.546L400.18 306.541V309.027H404.202V306.541L406.213 305.546L408.224 306.541V309.027H412.246V306.541L414.257 305.546L416.268 306.541V309.027H420.29V306.541L422.301 305.546L424.311 306.541V309.027H428.333V306.541L430.344 305.546L432.355 306.541V309.027H436.377V306.541L438.388 305.546L440.399 306.541V309.027H444.421V306.541L446.432 305.546L448.443 306.541V309.027H452.464V306.541L454.475 305.546L456.486 306.541V309.027H460.508V306.541L462.519 305.546L464.53 306.541V309.027H468.552V306.541L470.563 305.546L472.574 306.541V309.027H476.596V306.541L478.607 305.546L480.617 306.541V309.027H484.137L489.667 278.2L480.617 260.798V248.866L497.71 236.933L518.322 248.866V260.798L512.29 278.2L528.88 342.339H530.388V339.853L532.399 338.859L534.41 339.853V342.339H538.432V339.853L540.443 338.859L542.454 339.853V342.339H547.481L558.541 278.2L547.481 260.798V248.866L569.098 236.933L589.208 248.866V260.798L578.148 278.2L589.208 343.831H591.721V341.345L593.732 340.35L595.743 341.345V343.831H599.765V341.345L601.776 340.35L603.787 341.345V343.831H607.809V340.35H608.814V343.831V384.104L634.956 439.79H636.464V437.304L638.475 436.31L640.486 437.304V439.79H644.508V437.304L646.519 436.31L648.53 437.304V439.79H652.552V437.304L654.563 436.31L656.574 437.304V439.79H660.791V437.304L662.607 436.31L664.617 437.304V439.79H668.639V437.304L670.65 436.31L672.661 437.304V439.79H676.683V437.304L678.694 436.31L680.705 437.304V439.79H684.727V436.31H685.732V439.79V494.233H723.437V559.118L1103 548.676V923H0V834.5Z",
"M0 609.069L32.6776 585.203L23.1257 573.768L37.2022 566.807H54.2951L80.9399 530.511V522.059L90.9945 515.098H108.087L122.164 488.249L137.749 475.819L159.366 465.875V454.44L180.481 443.501L196.066 412.178L209.137 394.279V361.961V345.056V334.118L196.066 321.688L180.481 291.359L220.197 294.839H245.836V250.588H267.956H298.623L307.169 166.562H324.262V117.339V113.859H325.268V117.339H328.284V114.853L330.295 113.859L332.306 114.853V117.339H335.825V114.853L337.836 113.859L339.847 114.853V117.339H343.869V114.853L345.88 113.859L347.891 114.853V117.339H350.907L358.448 53.2003L350.907 35.7983V23.8655L373.53 11.9328L393.639 23.8655V35.7983L387.607 53.2003L393.639 84.0266H397.158V81.5406L399.169 80.5462L401.18 81.5406V84.0266H405.202V81.5406L407.213 80.5462L409.224 81.5406V84.0266H413.246V81.5406L415.257 80.5462L417.268 81.5406V84.0266H421.29V81.5406L423.301 80.5462L425.311 81.5406V84.0266H429.333V81.5406L431.344 80.5462L433.355 81.5406V84.0266H437.377V81.5406L439.388 80.5462L441.399 81.5406V84.0266H445.421V81.5406L447.432 80.5462L449.443 81.5406V84.0266H453.464V81.5406L455.475 80.5462L457.486 81.5406V84.0266H461.508V81.5406L463.519 80.5462L465.53 81.5406V84.0266H469.552V81.5406L471.563 80.5462L473.574 81.5406V84.0266H477.596V81.5406L479.607 80.5462L481.617 81.5406V84.0266H485.137L490.667 53.2003L481.617 35.7983V23.8655L498.71 11.9328L519.322 23.8655V35.7983L513.29 53.2003L529.88 117.339H531.388V114.853L533.399 113.859L535.41 114.853V117.339H539.432V114.853L541.443 113.859L543.454 114.853V117.339H548.481L559.541 53.2003L548.481 35.7983V23.8655L570.098 11.9328L590.208 23.8655V35.7983L579.148 53.2003L590.208 118.831H592.721V116.345L594.732 115.35L596.743 116.345V118.831H600.765V116.345L602.776 115.35L604.787 116.345V118.831H608.809V115.35H609.814V118.831V159.104L635.956 214.79H637.464V212.304L639.475 211.31L641.486 212.304V214.79H645.508V212.304L647.519 211.31L649.53 212.304V214.79H653.552V212.304L655.563 211.31L657.574 212.304V214.79H661.791V212.304L663.607 211.31L665.617 212.304V214.79H669.639V212.304L671.65 211.31L673.661 212.304V214.79H677.683V212.304L679.694 211.31L681.705 212.304V214.79H685.727V211.31H686.732V214.79V269.233H724.437V334.118L1104 323.676V698H1L0.5Z"
error:
Error: <path> attribute d: Expected number, "…323.676V698H1L0.5Z".
After the second click, the errors explode in number, but appear to be for vectors I can't find in my svg (this is when the image returns to it's original position). I'm not sure where the numbers are coming from, which makes me think maybe they are generated by Spring. At any rate, everything looks fine in the actual browser window, so I don't think these errors are legit (in the sense that the image looks good, and the terminal point looks right, the animation happens, and even can be repeated...so what exactly is it complaining about).
The question is:
Is there actually something wrong with these vectors?
If not, I'm not sure how to fix the error. I'm not sure why d would expect a number when it should expect a set of svg instructions. Any advice would be welcome!
The spring code is here:
const animationProps = useSpring({
castle: castleCoord[curIndex],
//moon: moonsCY[curIndex]
});
I am trying to move the castle independent of several elements in the svg.
I get the exact same error by creating a bare minimum svg tag and adding 2 path elements to it with the "d" attributes set to the vector strings you provided, so I don't think its anything specific to React-spring. Browsers are extremely forgiving with how they parse svg xml so even when there are errors it often still renders fine.
If I put that same svg through the svg minifier/validator tool here: https://jakearchibald.github.io/svgomg/ , and then use that cleaned version in the html instead, there are no more errors. But since i'm not sure what its supposed to look like I can't really say if that's a solution or not, but its worth trying.
It turned out to be something about the editor I had used to create the SVGs. After making changes to the base files, I was able to fix related arity errors, and these errors also went away. Maybe not an exciting answer, but if the two SVGs are very similar but still throwing these errors, consider going back and remaking the SVGs (in this case, I literally copy-pasted the SVG back in place and it changed the markup).

Displaying Parse Data to ContainerList

I want to display data from Parse in a list from GamesScores class using Container in Codename One, this is what I've tried so far and it's not showing anything nor giving any errors:
Container container = findListCont();
container.setLayout(BoxLayout.y());
container.setScrollableY(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
List<ParseObject> results = (List<ParseObject>) query.find();
System.out.println("Size: " + results.size());
container.addComponent(results, f);
Please help me out, I'm a new in Codename One. If there tutorials on it, please share or anything to help me achieve the desired results.
I'm actually shocked this isn't failing. You are using the add constraint to place the object result as a constraint and you add the form object into the container...
You need to loop over the results and convert them to components to add into the layout. It also seems that you are using the old GUI builder which I would recommend against.
Generally something like this rough pseudo code should work assuming you are using a box Y layout:
for(ParseObject o : results) {
MultiButton mb = new MultiButton(o.getDisplayValue());
f.add(mb);
}
f.revalidate();

storing images into to a cell in matlab

I understand that similar questions have been asked before but I have tried the other solutions and had no luck. Would really appreciate some help!
I want to 1.load a file of images, 2.read them with imread, 3.put that in a cell, 4.run my function stepwise on each array in the cell.
here is my function for 1 image/file
function sym_file(filename) %this calls for the image file name
j=im2double(rgb2gray(imread(filename)));
%reads the image, turns int into grayscale and double
if rem(size(j,2),2)~=0,j(:,1)=[];
if rem(size(j,1),2)~=0,j(1,:)=[];
end
end
%this made sure the rows and columns are even
jr=fliplr(j);
left=(j(:,1:size(j,2)/2));
right=(jr(:,1:size(j,2)/2));
t=sum(left,2);
u=sum(right,2);
symmetry= (left-right)./255;
symmetry2=reshape(symmetry,1,(numel(symmetry)));
imbalance=mean(symmetry2)
asymmetry=sqrt(mean(symmetry2.^2))
%runs calculations on image
figure('Name',num2str(filename),'NumberTitle','off')
subplot(3,2,1)
histogram(symmetry2,200)
title(['symmetry:' num2str(asymmetry)])
subplot(3,2,2)
imshow(j)
title(['imbalance:' num2str(imbalance)])
subplot(3,2,3)
imshow(left)
title('left')
subplot(3,2,4)
imshow(fliplr(right))
title('right')
impixelinfo;
subplot(3,2,5)
plot(1:length(t),t,'-r',1:length(u),u,'-b')
title('results,red=left/blue=right')
%printing results in a figure
So I would like to do this with a file of images rather than doing it file by file. What's the best way? Also, if someone knows how to store the data/figures in files that would be a bonus also.
Let me see if I got this straight: you have a set of images and you store them in a cell. You then want to apply a function to each image (in other words: to each element of the cell).
If so, just use cellfun()
Example:
X = imread('http://sipi.usc.edu/database/preview/aerials/3.2.25.png','png');
Y = imread('http://sipi.usc.edu/database/preview/misc/5.3.01.png','png');
my_cell{1} = X;
my_cell{2} = Y;
my_fftcell = cellfun(#fft2,my_cell,'UniformOutput', false)
In this case I loaded 2 images X and Y and stored them into my_cell (the brackets {} indicate to MATLAB/Octave that it is a cell). I then created another cell called my_fftcell which is the fft2 applied over each image.
To get many files from a folder/directory, you can just loop over each file in that directory and store it into the cell. Something like this:
Loading multiple images in MATLAB

MATLAB - save image in structure array array{i,y} and retrieve with (image(i,y))?

My system:
Windows 8.1
MATLAB2015a
My issue: When I save a JPG image in a structure array, in this case stiAll{i,y}
fileName = strcat('group_',strGr,'_',strVal,'.jpg');
fileNameStr = char(fileName);
stiAll{i,y} = imread(fileNameStr);
and I try to retrieve the saved image with image(stiAll(i,y)) I get the following error message from MATLAB:
Invalid datatype for Image CData. Numeric or logical
matrix required for image CData.
If I save the image without the {i,y} suffix, so that the image is saved in a normal variable, not in a structure array, I can retrieve the image. However, for my programme I would need to save images in the respective cells of a structure array or something similar.
Any idea how to get this done successfully?
Thanks
J
stiAll{i,y} = imread(fileNameStr); looks like a cellArray. And you try to plot it image(stiAll(i,y)) now as Matrix. Try image(stiAll{i,y})

Byte Array copy in Jsp

I am trying to append 2 images (as byte[] ) in GoogleAppEngine Java and then ask HttpResponseServlet to display it.
However, it does not seem like the second image is being appended.
Is there anything wrong with the snippet below?
...
resp.setContentType("image/jpeg");
byte[] allimages = new byte[1000000]; //1000kB in size
int destPos = 0;
for(Blob savedChart : savedCharts) {
byte[] imageData = savedChart.getBytes(); //imageData is 150k in size
System.arraycopy(imageData, 0, allimages, destPos, imageData.length);
destPos += imageData.length;
}
resp.getOutputStream().write(allimages);
return;
Regards
I would expect the browser/client to issue 2 separate requests for these images, and the servlet would supply each in turn.
You can't just concatenate images together (like most other data structures). What about headers etc.? At the moment you're providing 2 jpegs butted aainst one another and a browser won't handle that at all.
If you really require 2 images together, you're going to need some image processing library to do this for you (or perhaps, as noted, AWT). Check out the ImageIO library.
Seem that you have completely wrong concept about image file format and how they works in HTML.
In short, the arrays are copied very well without problem. But it is not the way how image works.
You will need to do AWT to combine images in Java

Resources